Class: SolidusImportProducts::SaveProduct
- Inherits:
-
Object
- Object
- SolidusImportProducts::SaveProduct
- Includes:
- ImportHelper
- Defined in:
- app/services/solidus_import_products/save_product.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#product ⇒ Object
Returns the value of attribute product.
-
#product_information ⇒ Object
Returns the value of attribute product_information.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'app/services/solidus_import_products/save_product.rb', line 3 def logger @logger end |
#product ⇒ Object
Returns the value of attribute product.
3 4 5 |
# File 'app/services/solidus_import_products/save_product.rb', line 3 def product @product end |
#product_information ⇒ Object
Returns the value of attribute product_information.
3 4 5 |
# File 'app/services/solidus_import_products/save_product.rb', line 3 def product_information @product_information end |
Class Method Details
.call(options = {}) ⇒ Object
7 8 9 |
# File 'app/services/solidus_import_products/save_product.rb', line 7 def self.call( = {}) new.call() end |
Instance Method Details
#call(args = { product: nil, product_information: nil }) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/solidus_import_products/save_product.rb', line 11 def call(args = { product: nil, product_information: nil }) self.logger = SolidusImportProducts::Logger.instance self.product_information = args[:product_information] self.product = args[:product] logger.log("SAVE PRODUCT: #{product.inspect}", :debug) unless product.valid? msg = "A product could not be imported - here is the information we have:\n" \ "#{product_information}, #{product.inspect} #{product.errors..join(', ')}" logger.log(msg, :error) raise SolidusImportProducts::Exception::ProductError, msg end product.save # Associate our new product with any taxonomies that we need to worry about if product_information[:attributes].key?(:taxonomies) && product_information[:attributes][:taxonomies] associate_product_with_taxon(product, product_information[:attributes][:taxonomies], true) end # Finally, attach any images that have been specified product_information[:images].each do |filename| find_and_attach_image_to(product, filename) end logger.log("#{product.name} successfully imported.\n") true end |