Class: SolidusImportProducts::CreateVariant
- Inherits:
-
Object
- Object
- SolidusImportProducts::CreateVariant
- Includes:
- ImportHelper
- Defined in:
- app/services/solidus_import_products/create_variant.rb
Overview
CreateVariant This method assumes that some form of checking has already been done to make sure that we do actually want to create a variant. It performs a similar task to a product, but it also must pick up on size/color options
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.
-
#variant ⇒ Object
Returns the value of attribute variant.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'app/services/solidus_import_products/create_variant.rb', line 8 def logger @logger end |
#product ⇒ Object
Returns the value of attribute product.
8 9 10 |
# File 'app/services/solidus_import_products/create_variant.rb', line 8 def product @product end |
#product_information ⇒ Object
Returns the value of attribute product_information.
8 9 10 |
# File 'app/services/solidus_import_products/create_variant.rb', line 8 def product_information @product_information end |
#variant ⇒ Object
Returns the value of attribute variant.
8 9 10 |
# File 'app/services/solidus_import_products/create_variant.rb', line 8 def variant @variant end |
Class Method Details
.call(options = {}) ⇒ Object
12 13 14 |
# File 'app/services/solidus_import_products/create_variant.rb', line 12 def self.call( = {}) new.call() end |
Instance Method Details
#call(args = { product: nil, product_information: nil }) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/solidus_import_products/create_variant.rb', line 16 def call(args = { product: nil, product_information: nil }) self.logger = SolidusImportProducts::Logger.instance self.product_information = args[:product_information] self.product = args[:product] return if product_information.nil? load_or_initialize_variant product_information.each do |field, value| if field == :variant_options value.each { |variant_field, variant_value| (variant_field, variant_value) } elsif field == :attributes value.each { |attr_field, attr_value| variant.send("#{attr_field}=", attr_value) if variant.respond_to?("#{attr_field}=") } end end begin variant.save product_information[:variant_images].each do |filename| find_and_attach_image_to(variant, filename) end stock_items logger.log("Variant of SKU #{variant.sku} successfully imported.\n", :debug) rescue StandardError => e = "A variant could not be imported - here is the information we have:\n" += "#{product_information}, #{variant.errors..join(', ')}\n" += e..to_s logger.log(, :error) raise SolidusImportProducts::Exception::VariantError, end variant end |