Class: Spree::ProductDuplicator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product) ⇒ ProductDuplicator


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

def initialize(product)
  @product = product
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


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spree/core/product_duplicator.rb', line 9

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