diff --git a/app/models/concerns/product_stock.rb b/app/models/concerns/product_stock.rb index 9ca52370fc..6758080ef5 100644 --- a/app/models/concerns/product_stock.rb +++ b/app/models/concerns/product_stock.rb @@ -6,20 +6,12 @@ module ProductStock extend ActiveSupport::Concern def on_demand - if variants? - raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1 + raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1 - variants.first.on_demand - else - master.on_demand - end + variants.first.on_demand end def on_hand - if variants? - variants.map(&:on_hand).reduce(:+) - else - master.on_hand - end + variants.map(&:on_hand).reduce(:+) end end diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index bedde7561a..7110bad78d 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -251,11 +251,6 @@ module Spree permalink.present? ? permalink : (permalink_was || UrlGenerator.to_url(name)) end - # the master variant is not a member of the variants array - def variants? - variants.any? - end - def tax_category if self[:tax_category_id].nil? TaxCategory.find_by(is_default: true) diff --git a/lib/spree/core/product_duplicator.rb b/lib/spree/core/product_duplicator.rb index 659d2c5c6d..68a1ced2d7 100644 --- a/lib/spree/core/product_duplicator.rb +++ b/lib/spree/core/product_duplicator.rb @@ -11,9 +11,7 @@ module Spree def duplicate new_product = duplicate_product - - # don't dup the actual variants, just the characterising types - new_product.option_types = product.option_types if product.variants? + new_product.option_types = product.option_types new_product.save! new_product diff --git a/spec/lib/spree/core/product_duplicator_spec.rb b/spec/lib/spree/core/product_duplicator_spec.rb index 05813f104d..452aa51c12 100644 --- a/spec/lib/spree/core/product_duplicator_spec.rb +++ b/spec/lib/spree/core/product_duplicator_spec.rb @@ -9,7 +9,7 @@ describe Spree::Core::ProductDuplicator do taxons: [], product_properties: [property], master: variant, - variants?: false + option_types: [] end let(:new_product) do @@ -63,6 +63,7 @@ describe Spree::Core::ProductDuplicator do expect(new_product).to receive(:updated_at=).with(nil) expect(new_product).to receive(:deleted_at=).with(nil) expect(new_product).to receive(:master=).with(new_variant) + expect(new_product).to receive(:option_types=).with([]) expect(new_variant).to receive(:sku=).with("") expect(new_variant).to receive(:deleted_at=).with(nil)