Class: Spree::ProductDuplicator
- Inherits:
-
Object
- Object
- Spree::ProductDuplicator
- Defined in:
- lib/spree/core/product_duplicator.rb
Constant Summary collapse
- @@clone_images_default =
true
Instance Attribute Summary collapse
-
#product ⇒ Object
Returns the value of attribute product.
Instance Method Summary collapse
- #duplicate ⇒ Object
-
#initialize(product, include_images = @@clone_images_default) ⇒ ProductDuplicator
constructor
A new instance of ProductDuplicator.
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
#product ⇒ Object
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
#duplicate ⇒ Object
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 |