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
Fixes ability to zero-out Price via Price List (#14432)
Damian Legawieca25a178c1305
diff --git a/spree/core/lib/spree/core/pricing/resolver.rb b/spree/core/lib/spree/core/pricing/resolver.rbindex 7150ff8edc..5b5d7aad1a 100644--- a/spree/core/lib/spree/core/pricing/resolver.rb+++ b/spree/core/lib/spree/core/pricing/resolver.rb@@ -62,18 +62,19 @@ module Spreedef find_price_for_list(price_list)currency = context.currency&.upcase+ # Zero is a valid override (free for this list); only nil placeholder+ # rows (materialized by PriceList#add_products) are skipped.if prices.loaded?prices.detect do |p|p.currency == currency &&p.price_list_id == price_list.id &&- p.amount.present? &&- !p.amount.zero?+ !p.amount.nil?endelsecontext.variant.prices.with_currency(currency).where(price_list_id: price_list.id)- .non_zero+ .where.not(amount: nil).firstendenddiff --git a/spree/core/spec/lib/spree/pricing/resolver_spec.rb b/spree/core/spec/lib/spree/pricing/resolver_spec.rbindex fbe2ffb2a7..48be8ac868 100644--- a/spree/core/spec/lib/spree/pricing/resolver_spec.rb+++ b/spree/core/spec/lib/spree/pricing/resolver_spec.rb@@ -42,6 +42,44 @@ describe Spree::Pricing::Resolver doendend+ context 'with a zero-amount price list price' do+ let!(:price_list) { create(:price_list, :active, store: store) }+ let!(:list_price) { create(:price, variant: variant, currency: currency, amount: 0, price_list: price_list) }++ it 'returns the free price list price instead of the base price' do+ price = resolver.resolve+ expect(price).to eq(list_price)+ expect(price.amount).to eq(0)+ expect(price.price_list_id).to eq(price_list.id)+ end++ it 'returns the free price list price when prices are already loaded' do+ variant.prices.load+ price = resolver.resolve+ expect(price).to eq(list_price)+ expect(price.amount).to eq(0)+ end+ end++ context 'with a placeholder (nil amount) price list price' do+ let!(:price_list) { create(:price_list, :active, store: store) }+ let!(:list_price) { create(:price, variant: variant, currency: currency, amount: nil, price_list: price_list) }++ it 'falls back to the base price' do+ base_price = variant.prices.base_prices.with_currency(currency).first+ price = resolver.resolve+ expect(price).to eq(base_price)+ expect(price.amount).to eq(19.99)+ end++ it 'falls back to the base price when prices are already loaded' do+ variant.prices.load+ price = resolver.resolve+ expect(price.amount).to eq(19.99)+ expect(price.price_list_id).to be_nil+ end+ end+context 'with multiple applicable price lists' dolet!(:second_position_list) { create(:price_list, :active, store: store, position: 2) }let!(:second_position_price) { create(:price, variant: variant, currency: currency, amount: 17.99, price_list: second_position_list) }