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
[CSV Import] fix assigning product to store (#14051)
Kacper Mękarski4043d9e2f083
diff --git a/spree/core/app/models/spree/import.rb b/spree/core/app/models/spree/import.rbindex 9956739a6c..be46f95e3e 100644--- a/spree/core/app/models/spree/import.rb+++ b/spree/core/app/models/spree/import.rb@@ -62,6 +62,7 @@ module Spreeevent :complete dotransition from: :processing, to: :completedend+ after_transition to: :completed, do: :touch_storeafter_transition to: :completed, do: :publish_import_completed_event# NOTE: send_import_completed_email and update_loader_in_import_view# are now handled by Spree::Admin::ImportSubscriber listening to 'import.completed' event@@ -181,6 +182,10 @@ module Spree"#{Spree.t(type.demodulize.pluralize.downcase)} #{number}"end+ def touch_store+ store.touch+ end+def publish_import_completed_eventpublish_event('import.completed')enddiff --git a/spree/core/app/services/spree/imports/row_processors/product_variant.rb b/spree/core/app/services/spree/imports/row_processors/product_variant.rbindex d8466fda82..4c7de55a41 100644--- a/spree/core/app/services/spree/imports/row_processors/product_variant.rb+++ b/spree/core/app/services/spree/imports/row_processors/product_variant.rb@@ -66,8 +66,12 @@ module Spreeproduct = existing_product if existing_product.present?end- product = assign_attributes_to_product(product)- product.save!+ # Store is touched when the import completes+ Spree::Store.no_touching do+ product = assign_attributes_to_product(product)+ product.save!+ end+if has_product_attributes?handle_metafields(product)handle_categories(product)diff --git a/spree/core/spec/models/spree/import_spec.rb b/spree/core/spec/models/spree/import_spec.rbindex db3fd18d35..523f3ec84d 100644--- a/spree/core/spec/models/spree/import_spec.rb+++ b/spree/core/spec/models/spree/import_spec.rb@@ -95,6 +95,10 @@ RSpec.describe Spree::Import, :job, type: :model doexpect { import.complete! }.to change(import, :status).from('processing').to('completed')end+ it 'touches the store' do+ expect { import.complete! }.to change { store.reload.updated_at }+ end+it 'publishes import.completed event' doexpect(import).to receive(:publish_import_completed_event)import.complete!diff --git a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rbindex 55d6cb0c40..c03fa31163 100644--- a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb+++ b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb@@ -56,6 +56,10 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service doexpect(variant.stock_items.first.stock_location).to eq store.default_stock_locationend+ it 'does not touch the store when associating the product' do+ expect { subject.process! }.not_to change { store.reload.updated_at }+ end+context 'when updating an existing master variant' dolet!(:existing_product) { create(:product, slug: 'denim-shirt', name: 'Old Name', stores: [store]) }