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
V-3105 Fixed product imports prices changes for existing products/var… (#13225)
Damian Legawiec98862e5a8cfa
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 9487f3404e..9e32a350d2 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -395,11 +395,10 @@ module Spreeenddef set_price(currency, amount, compare_at_amount = nil)- prices.find_or_initialize_by(currency: currency) do |price|- price.amount = amount- price.compare_at_amount = compare_at_amount if compare_at_amount.present?- price.save!- end+ price = prices.find_or_initialize_by(currency: currency)+ price.amount = amount+ price.compare_at_amount = compare_at_amount if compare_at_amount.present?+ price.save!enddef set_stock(count_on_hand, backorderable = nil, stock_location = nil)diff --git a/core/spec/services/spree/imports/row_processors/product_variant_spec.rb b/core/spec/services/spree/imports/row_processors/product_variant_spec.rbindex 839d1cdf0d..4f9c48e55d 100644--- a/core/spec/services/spree/imports/row_processors/product_variant_spec.rb+++ b/core/spec/services/spree/imports/row_processors/product_variant_spec.rb@@ -96,6 +96,19 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service doexpect(color_option_type.option_values.find_by(presentation: 'Blue')).to be_presentexpect(size_option_type.option_values.find_by(presentation: 'XS')).to be_presentend++ context 'when importing a variant row for existing variant' do+ let(:color_option_type) { Spree::OptionType.find_by(name: 'color') || create(:option_type, name: 'color', presentation: 'Color') }+ let(:size_option_type) { Spree::OptionType.find_by(name: 'size') || create(:option_type, name: 'size', presentation: 'Size') }+ let(:blue_option_value) { create(:option_value, name: 'Blue', presentation: 'Blue', option_type: color_option_type) }+ let(:xs_option_value) { create(:option_value, name: 'XS', presentation: 'XS', option_type: size_option_type) }+ let!(:variant) { create(:variant, product: product, sku: 'DENIM-SHIRT-XS-BLUE', price: 50.99, option_values: [blue_option_value, xs_option_value]) }++ it 'updates the variant' do+ expect { subject.process! }.to change { variant.reload.price }.from(50.99).to(62.99)+ expect(variant.option_values.map(&:presentation).sort).to contain_exactly('Blue', 'XS')+ end+ endendcontext 'when importing a variant row with a new option type/value' do