so what happen is, that somehow an unsaved LineIte...
# general
r
so what happen is, that somehow an unsaved LineItem is added to the order.line_items 🤔
r
this is the one i am using
k
or right, sorry.
order.contents
is an instance of that
r
yea 🙂
because one of the line_items is an unsaved / nil
and i can’t figure out who adds that line item
k
so maybe it’s another line item?
r
yes, this one even returns true for added item
I added a log to see
Copy code
<http://Rails.logger.info|Rails.logger.info>("add_to_line_item: #{line_item.save!}")
this says true
k
ok, I’m seeing that there’s a PromotionHandler called. Maybe you have a promotion that is adding a line item which is acting in a strange way?
or some other custom code?
r
i will try and comment it, one sec
no change when commenting the promo handler
it’s prob some kind of extension that messes with something 🤯
okey, its the subscription extension
k
let us know what happens please
r
yea, will in a minute
i was creating subscription items manually by code after i added the item to the the order. (By calling
SolidusSubscriptions::LineItem.create
). This does something with the order by adding a line item. I guess it could not be saved because i did not pass the item returned by
order.contents.add
to
SolidusSubscriptions::LineItem.create
So on the next loop it crashed. Now the code looks like this:
Copy code
variants_ids.each do |variant_id|
  variant = ::Spree::Variant.find(variant_id)
  line_item = order.contents.add(variant, 1)
  subscription_line_items << SolidusSubscriptions::LineItem.create({
                                                                     spree_line_item: line_item,
                                                                     quantity: 1,
                                                                     subscribable_id: variant.id,
                                                                     interval_length: 1,
                                                                     interval_units: subscription.billing_period_unit == 'year' ? 'year' : 'month',
                                                                     order: order
                                                                   })
end
k
so it’s all good now?
r
seems like it yes, going to test a bit more
The missing line was:
spree_line_item: line_item
in attributes to create
👍 1