Class: SolidusImportProducts::ProcessRow
- Inherits:
-
Object
- Object
- SolidusImportProducts::ProcessRow
- Defined in:
- app/services/solidus_import_products/process_row.rb
Constant Summary collapse
- VARIANT_FIELD_NAME =
:name
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#product_imports ⇒ Object
Returns the value of attribute product_imports.
-
#product_information ⇒ Object
Returns the value of attribute product_information.
-
#row ⇒ Object
Returns the value of attribute row.
-
#skus_of_products_before_import ⇒ Object
Returns the value of attribute skus_of_products_before_import.
-
#variant_field ⇒ Object
Returns the value of attribute variant_field.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(args = { parser: nil, product_imports: nil, row: nil, col: nil, skus_of_products_before_import: nil }) ⇒ ProcessRow
constructor
A new instance of ProcessRow.
Constructor Details
#initialize(args = { parser: nil, product_imports: nil, row: nil, col: nil, skus_of_products_before_import: nil }) ⇒ ProcessRow
Returns a new instance of ProcessRow.
7 8 9 10 11 12 13 14 15 16 |
# File 'app/services/solidus_import_products/process_row.rb', line 7 def initialize(args = { parser: nil, product_imports: nil, row: nil, col: nil, skus_of_products_before_import: nil }) self.parser = args[:parser] self.product_imports = args[:product_imports] self.row = args[:row] self.col = args[:col] self.variant_field = VARIANT_FIELD_NAME self.skus_of_products_before_import = args[:skus_of_products_before_import] self.logger = SolidusImportProducts::Logger.instance self.product_information = { variant_options: {}, images: [], variant_images: [], product_properties: {}, attributes: {} } end |
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def col @col end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def logger @logger end |
#parser ⇒ Object
Returns the value of attribute parser.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def parser @parser end |
#product_imports ⇒ Object
Returns the value of attribute product_imports.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def product_imports @product_imports end |
#product_information ⇒ Object
Returns the value of attribute product_information.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def product_information @product_information end |
#row ⇒ Object
Returns the value of attribute row.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def row @row end |
#skus_of_products_before_import ⇒ Object
Returns the value of attribute skus_of_products_before_import.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def skus_of_products_before_import @skus_of_products_before_import end |
#variant_field ⇒ Object
Returns the value of attribute variant_field.
3 4 5 |
# File 'app/services/solidus_import_products/process_row.rb', line 3 def variant_field @variant_field end |
Class Method Details
.call(options = {}) ⇒ Object
18 19 20 |
# File 'app/services/solidus_import_products/process_row.rb', line 18 def self.call( = {}) new().call end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/solidus_import_products/process_row.rb', line 22 def call extract_product_information product_information_default_values logger.log(product_information.to_s, :debug) variant_column = col[variant_field] product = Spree::Product.find_by(variant_field.to_s => row[variant_column]) unless product if skus_of_products_before_import.include?(product_information[:attributes][:sku]) raise SolidusImportProducts::Exception::ProductError, "SKU #{product_information[:attributes][:sku]} exists, but #{variant_field}: #{row[variant_column]} not exists!! " end product = Spree::Product.new end unless product_imports.product?(product) create_or_update_product(product) product_imports.add_product(product) end SolidusImportProducts::CreateVariant.call(product: product, product_information: product_information) end |