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

[Checkout] Shipping fee not updated after editing order #12907

Open
drummer83 opened this issue Oct 11, 2024 · 1 comment
Open

[Checkout] Shipping fee not updated after editing order #12907

drummer83 opened this issue Oct 11, 2024 · 1 comment
Assignees
Labels
bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround.

Comments

@drummer83
Copy link
Contributor

Description

This was found while testing #12880 and might be related to #11360.

If an order is updated by the customer after reaching step 3 of the checkout already, then the shipping fees will only be updated on the order summary page, but it will not be updated on the order confirmation screen and in the email. This results in an incorrect order total (on confirmation screen and in the email).

Expected Behavior

After updating the order, the order total on the order summary page should match the order total on the order confirmation page.

Actual Behaviour

After updating the order, the order total on the order summary page is different than the order total on the order confirmation page. This is because the shipping fee is not updated along with the order.

Steps to Reproduce

  1. Create a shipping method with a fee using the flat percent calculator.
  2. As a customer start an order with that shipping method and proceed to step three (order summary) of the checkout but don't complete the order.
  3. Take note of the order total and the shipping fee.
  4. Continue shopping, i.e. click on the shop's name next to the cart icon in the top right corner.
  5. Add one or more products to your cart.
  6. Click checkout again - you should land on step 3 (order summary directly).
  7. Take note of the order total and the shipping fee - both should be updated correctly, including your added products.
  8. Complete the order.
  9. Compare the numbers of order total and shipping fee again. The shipping fee is the old value before adding products and the order total is less than on the order summary page. ❌

Animated Gif/Screenshot

Order summary page after updating the order:
image

Order confirmation page after completing the order:
image

Workaround

Severity

bug-s2: a non-critical feature is broken, no workaround

Your Environment

  • Version used:
  • Browser name and version:
  • Operating System and version (desktop or mobile):

Possible Fix

@drummer83 drummer83 added the bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround. label Oct 11, 2024
@github-project-automation github-project-automation bot moved this to All the things 💤 in OFN Delivery board Oct 11, 2024
@sigmundpetersen sigmundpetersen moved this from All the things 💤 to Dev ready 👋 in OFN Delivery board Oct 11, 2024
@rioug rioug self-assigned this Oct 13, 2024
@rioug
Copy link
Collaborator

rioug commented Oct 14, 2024

Similar to #12880 but the cause is different,
Shipment fees are recalculated in various places ,
Spree::Order :

def update_shipping_fees!
shipments.each do |shipment|
next if shipment.shipped?
update_adjustment! shipment.fee_adjustment if shipment.fee_adjustment
save_or_rescue_shipment(shipment)
end
end

Triggered by this callback
before_save :update_shipping_fees!, if: :complete?

Spree::Shipment :

def ensure_correct_adjustment
if fee_adjustment
fee_adjustment.originator = shipping_method
fee_adjustment.label = adjustment_label
fee_adjustment.amount = selected_shipping_rate.cost if fee_adjustment.open?
fee_adjustment.save!
fee_adjustment.reload
elsif shipping_method
shipping_method.create_adjustment(adjustment_label,
self,
true,
"open")
reload # ensure adjustment is present on later saves
end

Triggered by this callback
after_save :ensure_correct_adjustment, :update_adjustments

ensure_correct_adjustment is actually wrong , on line 282 it used selected_shipping_rate.cost instead of using the calculator linked to the originator.
We'll need to reassess if we need this ensure_correct_adjustment or fix it to update the adjustment as expected.

@mkllnk mkllnk moved this from Dev ready 👋 to In Progress ⚙ in OFN Delivery board Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround.
Projects
Status: In Progress ⚙
Development

No branches or pull requests

2 participants