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.
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
#product ⇒ Object
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
#duplicate ⇒ Object
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 |