Merge pull request #8809 from Matt-Yorkley/dead-code-variants-check

Remove dead code: Product#variants?
This commit is contained in:
Maikel
2022-10-25 10:49:01 +11:00
committed by GitHub
4 changed files with 6 additions and 20 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)