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
Exclude discontinued variants from product stock availability
Łukasz Adamczykb771b944315d
diff --git a/spree/core/app/models/spree/product.rb b/spree/core/app/models/spree/product.rbindex 2b38498ddd..e9f7f3ad21 100644--- a/spree/core/app/models/spree/product.rb+++ b/spree/core/app/models/spree/product.rb@@ -594,7 +594,7 @@ module Spreedef any_variant_in_stock_or_backorderable?if has_variants?- variants.in_stock_or_backorderable.exists?+ variants.in_stock_or_backorderable.not_discontinued.exists?elsedefault_variant.in_stock_or_backorderable?enddiff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rbindex 7cdf879d7e..94e5c2256f 100644--- a/spree/core/spec/models/spree/product_spec.rb+++ b/spree/core/spec/models/spree/product_spec.rb@@ -1126,6 +1126,20 @@ describe Spree::Product, type: :model doendend+ context 'when the only stocked variant is discontinued' do+ let!(:variant) { create(:variant, product: product) }++ before do+ Spree::StockItem.update_all(backorderable: false)+ product.default_variant.stock_items.first.set_count_on_hand(0)+ variant.stock_items.first.set_count_on_hand(10)+ variant.update_column(:discontinue_on, 1.day.ago)+ product.reload+ end++ it { expect(subject).to eq(false) }+ end+describe '#digital?' dolet(:product) { create(:product, shipping_category: shipping_category) }let(:shipping_category) { create(:shipping_category) }