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: kept price list prices to the list's own store variants
Damian Legawiec00e0bc062dc5
diff --git a/spree/api/app/controllers/spree/api/v3/admin/price_lists_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/price_lists_controller.rbindex eae21e0cf7..ef1c4784cc 100644--- a/spree/api/app/controllers/spree/api/v3/admin/price_lists_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/price_lists_controller.rb@@ -122,7 +122,7 @@ module Spreeenddef permitted_params- attrs = normalize_params(+ normalize_params(params.permit(:name, :description, :position,:starts_at, :ends_at, :match_policy,@@ -132,24 +132,6 @@ module Spreeprices: [:id, :variant_id, :currency, :min_quantity, :amount, :compare_at_amount]))- reject_foreign_variants(attrs)- end-- # The price rows resolve variant ids with no store scoping, so a- # list in this store could otherwise be populated with another- # store's variants. Drop any id that isn't in the current store- # before assignment.- def reject_foreign_variants(attrs)- if attrs[:prices].present?- incoming = Array(attrs[:prices])- store_variant_ids = current_store.variants.where(id: incoming.map { |r| r[:variant_id] }.compact).- pluck(:id).map(&:to_s).to_set- attrs[:prices] = incoming.select do |row|- row[:variant_id].blank? || store_variant_ids.include?(row[:variant_id].to_s)- end- end-- attrsendprivatediff --git a/spree/api/spec/controllers/spree/api/v3/admin/catalogs_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/catalogs_controller_spec.rbindex 3ee9215c06..f3bb9ec62e 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/catalogs_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/catalogs_controller_spec.rb@@ -43,6 +43,28 @@ RSpec.describe Spree::Api::V3::Admin::CatalogsController, type: :controller do# A percentage plus a volume rule is an automatic volume discount, and# both halves have to be settable in the one request that stands the# agreement up (docs/plans/6.0-price-list-automatic-pricing.md).+ it "ignores another store's variant in the inline prices" do+ foreign_variant = create(:product, store: create(:store)).default_variant+ own_variant = create(:product, store: store).default_variant++ post :create,+ params: {+ name: 'Contract',+ price_list: {+ prices: [+ { variant_id: foreign_variant.prefixed_id, currency: 'USD', amount: '0.01' },+ { variant_id: own_variant.prefixed_id, currency: 'USD', amount: '5.00' }+ ]+ }+ },+ as: :json++ expect(response).to have_http_status(:created)+ list = store.catalogs.find_by(name: 'Contract').price_list+ expect(list.prices.where(variant_id: foreign_variant.id)).to be_empty+ expect(list.prices.find_by(variant_id: own_variant.id).amount).to eq(5)+ end+it 'accepts the contextual rules that make automatic volume pricing work' dopost :create,params: {diff --git a/spree/core/app/workflows/spree/price_lists/update.rb b/spree/core/app/workflows/spree/price_lists/update.rbindex d26547f753..2bb096a344 100644--- a/spree/core/app/workflows/spree/price_lists/update.rb+++ b/spree/core/app/workflows/spree/price_lists/update.rb@@ -86,7 +86,18 @@ module Spreetouch_variants(variant_ids)end+ # Rows are written with upsert_all, which checks nothing, so a variant+ # outside the list's store is dropped here rather than trusted to every+ # caller to filter first.def price_rows+ rows = raw_price_rows+ store_variant_ids = price_list.store.variants.where(id: rows.map { |row| row[:variant_id] }).+ pluck(:id).map(&:to_s).to_set++ rows.select { |row| store_variant_ids.include?(row[:variant_id].to_s) }+ end++ def raw_price_rowsArray(@prices).filter_map do |raw|row = raw.respond_to?(:to_unsafe_h) ? raw.to_unsafe_h.with_indifferent_access : raw.with_indifferent_access