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 variant_count left short by spree:remove_master_variant
Łukasz Adamczyk3fb2ef49d11a
diff --git a/spree/core/lib/tasks/remove_master_variant.rake b/spree/core/lib/tasks/remove_master_variant.rakeindex 2dceec3915..a9263f87ad 100644--- a/spree/core/lib/tasks/remove_master_variant.rake+++ b/spree/core/lib/tasks/remove_master_variant.rake@@ -44,7 +44,7 @@ namespace :spree doendvariant_count = Spree::Variant.where(product_id: product.id, deleted_at: nil).count- product.update_column(:variant_count, variant_count) unless product.variant_count == variant_count+ product.update_column(:variant_count, variant_count)migrated += 1enddiff --git a/spree/core/spec/lib/tasks/remove_master_variant_spec.rb b/spree/core/spec/lib/tasks/remove_master_variant_spec.rbindex 1c7e3cbdc8..3d0dec62cd 100644--- a/spree/core/spec/lib/tasks/remove_master_variant_spec.rb+++ b/spree/core/spec/lib/tasks/remove_master_variant_spec.rb@@ -34,6 +34,11 @@ describe 'spree:remove_master_variant' doSpree::Variant.where(product_id: product.id).first.update_column(:is_master, true)product.update_column(:default_variant_id, nil)extra.times { create(:variant, product: product) }+ # Legacy rows counted variant_count under the old master-excluded rule. Mirror+ # that so the task must recompute correctly: deleting the master fires the+ # counter callback (out-of-band decrement) and a stale-value guard would leave+ # variant_count one short — matching this legacy baseline is what surfaces it.+ product.update_column(:variant_count, Spree::Variant.where(product_id: product.id, is_master: false).count)productend