Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order shipment_state not updating after being shipped #53

Open
indokathan opened this issue Apr 15, 2022 · 1 comment
Open

Order shipment_state not updating after being shipped #53

indokathan opened this issue Apr 15, 2022 · 1 comment

Comments

@indokathan
Copy link

We noticed that after shipping an order (from the admin), the shipment state would not change to shipped.

After digging around, it seems this is being caused by the way the order_recalculated event is being handled

The Solidus OrderUpdater class has this method, which updates the shipping state and other things:

def update
  order.transaction do
    update_item_count
    update_shipment_amounts
    update_totals
    if order.completed?
      update_payment_state
      update_shipments
      update_shipment_state
    end
    Spree::Event.fire 'order_recalculated', order: order
    persist_totals
  end
end

When Spree::Event.fire 'order_recalculated', order: order is called, the KlarnaSubsciber calls order.update_klarna_shipments:

  def update_klarna_shipments
    return unless shipment_state_changed? && shipment_state == "shipped"

    captured_klarna_payments.each do |payment|
      payment.payment_method.gateway.shipping_info(
        payment.source.order_id,
        payment.source.capture_id,
        shipping_info: to_klarna(
          payment.payment_method.preferred_country
        ).shipping_info
      )
    end
  end

and the to_klarna method reloads the order:

  def to_klarna(country = :us)
    SolidusKlarnaPayments::OrderSerializer.new(reload, country)
  end

... the order reload in the method above causes the OrderUpdater to no longer see changed values, including the shipment_state.

Maybe this should be a Solidus issue, but figured I would start here since it is only happening with Klarna orders.

@kennyadsl
Copy link
Member

Thanks for reporting. This seems like a valid issue. Did you get why to_klarna is calling reload?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants