Class: Spree::ProductDuplicator

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

Constant Summary

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



8
9
10
11
# File 'lib/spree/core/product_duplicator.rb', line 8

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



3
4
5
# File 'lib/spree/core/product_duplicator.rb', line 3

def product
  @product
end

Instance Method Details

#duplicateObject



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

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