Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add the missing code needed when canceling quick checkout (#12605)
Damian Kaczmarczyka283001694b9
diff --git a/core/app/services/spree/checkout/update.rb b/core/app/services/spree/checkout/update.rbindex 346330eb91..8aa1ac8390 100644--- a/core/app/services/spree/checkout/update.rb+++ b/core/app/services/spree/checkout/update.rb@@ -9,8 +9,16 @@ module Spreebill_changed = address_with_country_iso_present?(params, 'bill')params[:order][:ship_address_attributes] = replace_country_iso_with_id(params[:order][:ship_address_attributes]) if ship_changedparams[:order][:bill_address_attributes] = replace_country_iso_with_id(params[:order][:bill_address_attributes]) if bill_changed- order.state = 'address' if (ship_changed || bill_changed) && order.has_checkout_step?('address')- order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')++ # for quick checkouts we cannot revert to previous states+ # we already have the address and delivery steps completed+ # however we need to update the shipping address with missing data+ # as previously we didn't have access to first/last name and street+ unless params[:do_not_change_state]+ order.state = 'address' if (ship_changed || bill_changed || quick_checkout_cancelled?(params)) && order.has_checkout_step?('address')+ order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')+ end+return success(order) if order.update_from_params(params, permitted_attributes, request_env)failure(order)@@ -31,6 +39,10 @@ module Spreeshipments_attributes.any? { |s| s.dig(:selected_shipping_rate_id) }end++ def quick_checkout_cancelled?(params)+ params.dig(:order, :ship_address_id) == 'CLEAR'+ endendendenddiff --git a/core/spec/services/spree/checkout/update_spec.rb b/core/spec/services/spree/checkout/update_spec.rbindex 5aef3d61f2..40a47a2467 100644--- a/core/spec/services/spree/checkout/update_spec.rb+++ b/core/spec/services/spree/checkout/update_spec.rb@@ -105,6 +105,22 @@ describe Spree::Checkout::Update, type: :service doexpect(order.state).to eq 'address'expect(order.ship_address.state.id).to eq state.idend++ it 'should not set order back to address state if do_not_change_state is true' do+ expect(order.state).not_to eq 'address'+ order_params[:do_not_change_state] = true+ update_service++ expect(order.state).not_to eq 'address'+ end++ it 'should set order back to address state if quick checkout cancelled' do+ expect(order.state).not_to eq 'address'+ order_params[:order][:ship_address_id] = 'CLEAR'+ update_service++ expect(order.state).to eq 'address'+ endendcontext 'at address state' do