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
Fix: Skipped removing a line from a cart that completed before the job ran (#15082)
Damian Legawiec88d4af61b291
diff --git a/spree/core/app/jobs/spree/variants/remove_line_item_job.rb b/spree/core/app/jobs/spree/variants/remove_line_item_job.rbindex c8c9addcda..b0e1e76b59 100644--- a/spree/core/app/jobs/spree/variants/remove_line_item_job.rb+++ b/spree/core/app/jobs/spree/variants/remove_line_item_job.rb@@ -7,6 +7,11 @@ module Spreeowner = line_item.ownerreturn if owner.nil?+ # A completed cart is a read-only audit record; the order it became+ # owns the lines now. The cart can complete between this job being+ # enqueued and running, and there is nothing left to remove from it.+ return if owner.is_a?(Spree::Cart) && owner.readonly?+# Carts and draft orders have different contracts: the cart side turns# a vetoed removal into a warning and still succeeds, the order side# fails outright. Routing an order-owned line through the cartdiff --git a/spree/core/spec/jobs/spree/variants/remove_line_item_job_spec.rb b/spree/core/spec/jobs/spree/variants/remove_line_item_job_spec.rbindex fea087127b..cdb58b1332 100644--- a/spree/core/spec/jobs/spree/variants/remove_line_item_job_spec.rb+++ b/spree/core/spec/jobs/spree/variants/remove_line_item_job_spec.rb@@ -30,6 +30,13 @@ module Spree}.to change { cart.reload.line_items.count }.by(-1)end+ it 'skips a cart that completed after the job was enqueued' do+ cart.update_columns(completed_at: Time.current)++ expect(Spree::Carts::UpsertItems).not_to receive(:new)+ expect { described_class.perform_now(line_item: cart_line_item.reload) }.not_to raise_error+ end+it 'routes through the cart workflow' doexpect(Spree::Carts::UpsertItems).to receive(:new).and_call_original