Class: Workarea::CopyProduct
- Inherits:
-
Object
- Object
- Workarea::CopyProduct
- Defined in:
- app/services/workarea/copy_product.rb
Instance Method Summary collapse
-
#initialize(product, attrs = {}) ⇒ CopyProduct
constructor
A new instance of CopyProduct.
- #perform ⇒ Object
Constructor Details
#initialize(product, attrs = {}) ⇒ CopyProduct
Returns a new instance of CopyProduct.
3 4 5 6 |
# File 'app/services/workarea/copy_product.rb', line 3 def initialize(product, attrs = {}) @product = product @attributes = Workarea.config.product_copy_default_attributes.merge(attrs) end |
Instance Method Details
#perform ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/workarea/copy_product.rb', line 8 def perform product_copy = @product.clone product_copy.assign_attributes(@attributes) product_copy.copied_from = @product existing_product = Catalog::Product.find(product_copy.id) rescue nil if existing_product.present? product_copy.errors.add( :id, I18n.t('workarea.errors.messages.must_be_unique') ) else product_copy.save! end product_copy end |