Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Name the seller on a checkout that did not divide

Damian Legawiec9db863a3b8bd
diff --git a/spree/core/app/workflows/spree/carts/complete.rb b/spree/core/app/workflows/spree/carts/complete.rb
index 7344ec22a6..bd3788a707 100644
--- a/spree/core/app/workflows/spree/carts/complete.rb
+++ b/spree/core/app/workflows/spree/carts/complete.rb
@@ -377,7 +377,16 @@ module Spree
return if order.placed?
partitions = Spree::Carts::PartitionBySeller.call(purchase: order).value
- return if partitions.size < 2
+
+ if partitions.one?
+ # Nothing to divide, but the sale still belongs to whoever made it:
+ # a basket entirely from one seller is that seller's order, and the
+ # column is what their own order list reads.
+ order.update_columns(seller_id: partitions.first.seller_id) if order.seller_id != partitions.first.seller_id
+ return
+ end
+
+ return if partitions.empty?
result = Spree::Carts::SplitBySeller.call(cart: cart, order: order, partitions: partitions)
failure(cart, code: 'split_failed', message: result.error) if result.failure?
diff --git a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb b/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
index aa8ab8a5ed..43c09f5e08 100644
--- a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/complete_split_spec.rb
@@ -39,6 +39,21 @@ module Spree
expect(result.value.line_items.map(&:seller_id).uniq).to eq([seller.id])
end
+ # Nothing to divide, but the sale is still that seller's — and their own
+ # order list reads the column, not the line items.
+ it 'stamps a single-seller order with its seller' do
+ result = described_class.call(cart: cart_for(seller, seller))
+
+ expect(result.value.seller).to eq(seller)
+ expect(seller.orders).to include(result.value)
+ end
+
+ it 'leaves an all-first-party order with no seller' do
+ result = described_class.call(cart: cart_for(nil, nil))
+
+ expect(result.value.seller_id).to be_nil
+ end
+
it 'splits a cart holding two sellers' do
result = described_class.call(cart: cart_for(seller, other_seller))