Remove duplicate_extra logic from ProductDuplicator

This commit is contained in:
Luis Ramos
2020-09-26 08:43:49 +01:00
parent 503c17f896
commit f6195f1159
4 changed files with 2 additions and 21 deletions

View File

@@ -261,17 +261,11 @@ module Spree
end
# for adding products which are closely related to existing ones
# define "duplicate_extra" for site-specific actions, eg for additional fields
def duplicate
duplicator = Spree::Core::ProductDuplicator.new(self)
duplicator.duplicate
end
# Called by Spree::Product::duplicate before saving.
def duplicate_extra(_parent)
master.sku = ''
end
# use deleted? rather than checking the attribute directly. this
# allows extensions to override deleted? if they want to provide
# their own definition.

View File

@@ -15,8 +15,6 @@ module Spree
# don't dup the actual variants, just the characterising types
new_product.option_types = product.option_types if product.variants?
# allow site to do some customization
new_product.__send__(:duplicate_extra, product) if new_product.respond_to?(:duplicate_extra)
new_product.save!
new_product
end
@@ -38,7 +36,7 @@ module Spree
def duplicate_master
master = product.master
master.dup.tap do |new_master|
new_master.sku = "COPY OF #{master.sku}"
new_master.sku = ""
new_master.deleted_at = nil
new_master.images = master.images.map { |image| duplicate_image image }
new_master.price = master.price

View File

@@ -64,7 +64,7 @@ describe Spree::Core::ProductDuplicator do
expect(new_product).to receive(:deleted_at=).with(nil)
expect(new_product).to receive(:master=).with(new_variant)
expect(new_variant).to receive(:sku=).with("COPY OF 12345")
expect(new_variant).to receive(:sku=).with("")
expect(new_variant).to receive(:deleted_at=).with(nil)
expect(new_variant).to receive(:images=).with([new_image])
expect(new_variant).to receive(:price=).with(variant.price)

View File

@@ -16,17 +16,6 @@ module Spree
expect(clone.master.sku).to eq ''
expect(clone.images.size).to eq product.images.size
end
it 'calls #duplicate_extra' do
Spree::Product.class_eval do
def duplicate_extra(old_product)
self.name = old_product.name.reverse
end
end
clone = product.duplicate
expect(clone.name).to eq product.name.reverse
end
end
context "product has no variants" do