Class: Spree::ProductDuplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/core/product_duplicator.rb

Constant Summary collapse

@@clone_images_default =
true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, include_images = @@clone_images_default) ⇒ ProductDuplicator

Returns a new instance of ProductDuplicator.



10
11
12
13
# File 'lib/spree/core/product_duplicator.rb', line 10

def initialize(product, include_images = @@clone_images_default)
  @product = product
  @include_images = include_images
end

Instance Attribute Details

#productObject

Returns the value of attribute product.



5
6
7
# File 'lib/spree/core/product_duplicator.rb', line 5

def product
  @product
end

Instance Method Details

#duplicateObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spree/core/product_duplicator.rb', line 15

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.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
end