Class: Gemgento::InventoryImport
- Defined in:
- app/models/gemgento/inventory_import.rb
Overview
Instance Attribute Summary collapse
-
#product ⇒ Object
Returns the value of attribute product.
Attributes inherited from Import
#header_row, #row, #spreadsheet
Instance Method Summary collapse
-
#process_row ⇒ Void
Set the Inventory for a Product.
Methods inherited from Import
#content_index_range, #default_options, #percentage_complete, #process, #process_later, #set_default_options, #set_default_process_errors, #set_total_rows, #value
Instance Attribute Details
#product ⇒ Object
Returns the value of attribute product.
8 9 10 |
# File 'app/models/gemgento/inventory_import.rb', line 8 def product @product end |
Instance Method Details
#process_row ⇒ Void
Set the Inventory for a Product.
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 40 41 42 43 44 45 46 47 48 |
# File 'app/models/gemgento/inventory_import.rb', line 15 def process_row self.product = Gemgento::Product.not_deleted.find_by(sku: row[header_row.index('sku').to_i]) return if self.product.magento_type == 'configurable' Gemgento::Store.all.each do |store| inventory = self.product.inventories.find_or_initialize_by(store: store) inventory.use_config_manage_stock = true inventory.use_config_backorders = true inventory.use_config_min_qty = true header_row.each do |attribute| next unless Gemgento::Inventory.column_names.include?(attribute) value = value(attribute, Gemgento::Inventory.columns_hash[attribute].type) inventory.assign_attributes(attribute => value) end inventory.sync_needed = true unless inventory.save self.process_errors << "Row ##{current_row}: #{inventory.errors[:base]}" end end rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e retries ||= 0 if retries += 1 <= @stores.count retry else self.process_errors << "Row ##{current_row}: #{e.}" end rescue Exception => e self.process_errors << "Row ##{current_row}: #{e.}" end |