Sha256: cf83b3fd9aeba0130abd9c3fda1480581c402ac55b154895828ca9b33bac9528

Contents?: true

Size: 651 Bytes

Versions: 62

Compression:

Stored size: 651 Bytes

Contents

module Workarea
  class CopyProduct
    def initialize(product, attrs = {})
      @product = product
      @attributes = Workarea.config.product_copy_default_attributes.merge(attrs)
    end

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

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/services/workarea/copy_product.rb
workarea-core-3.5.26 app/services/workarea/copy_product.rb
workarea-core-3.4.45 app/services/workarea/copy_product.rb
workarea-core-3.5.25 app/services/workarea/copy_product.rb
workarea-core-3.5.23 app/services/workarea/copy_product.rb
workarea-core-3.4.44 app/services/workarea/copy_product.rb
workarea-core-3.5.22 app/services/workarea/copy_product.rb
workarea-core-3.4.43 app/services/workarea/copy_product.rb
workarea-core-3.5.21 app/services/workarea/copy_product.rb
workarea-core-3.4.42 app/services/workarea/copy_product.rb
workarea-core-3.5.20 app/services/workarea/copy_product.rb
workarea-core-3.4.41 app/services/workarea/copy_product.rb
workarea-core-3.5.19 app/services/workarea/copy_product.rb
workarea-core-3.4.40 app/services/workarea/copy_product.rb
workarea-core-3.5.18 app/services/workarea/copy_product.rb
workarea-core-3.4.39 app/services/workarea/copy_product.rb
workarea-core-3.5.17 app/services/workarea/copy_product.rb
workarea-core-3.4.38 app/services/workarea/copy_product.rb
workarea-core-3.5.16 app/services/workarea/copy_product.rb
workarea-core-3.4.37 app/services/workarea/copy_product.rb