Class: Spree::Products::Duplicator

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/products/duplicator.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(product:, include_images: true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/spree/products/duplicator.rb', line 6

def call(product:, include_images: true)
  new_product = duplicate_product(product, include_images)

  # don't dup the actual variants, just the characterising types
  new_product.option_types = product.option_types if product.has_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.product_properties = duplicate_properties(product.product_properties) if new_product.persisted?

  new_product.persisted? ? success(new_product) : failure(new_product, duplicate_error_message(new_product))
end