Class: Spree::ImportRow
- Inherits:
-
Object
- Object
- Spree::ImportRow
- Defined in:
- app/models/spree/import_row.rb
Instance Method Summary collapse
- #add_row_to_import_view ⇒ Object
- #attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
- #data_json ⇒ Object
- #process! ⇒ Object
- #to_schema_hash ⇒ Object
- #update_footer_in_import_view ⇒ Object
Instance Method Details
#add_row_to_import_view ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/models/spree/import_row.rb', line 84 def add_row_to_import_view return unless defined?(broadcast_append_to) # we need to render this partial with store context to properly generate image URLs with_store_context do broadcast_append_to "import_#{import.id}_rows", target: 'rows', partial: 'spree/admin/imports/row', locals: { row: self, import: import } end end |
#attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/spree/import_row.rb', line 65 def attribute_by_schema_field(schema_field, mappings = nil) mappings ||= import.mappings.mapped mapping = mappings.find { |m| m.schema_field == schema_field } return unless mapping&.mapped? data_json[mapping.file_column] end |
#data_json ⇒ Object
46 47 48 49 50 |
# File 'app/models/spree/import_row.rb', line 46 def data_json @data_json ||= JSON.parse(data) rescue JSON::ParserError {} end |
#process! ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/models/spree/import_row.rb', line 74 def process! start_processing! self.item = import.row_processor_class.new(self).process! complete! rescue StandardError => e Rails.error.report(e, handled: true, context: { import_row_id: id }, source: 'spree.core') self.validation_errors = e. fail! end |
#to_schema_hash ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/spree/import_row.rb', line 52 def to_schema_hash @to_schema_hash ||= begin mappings = import.mappings.mapped schema_fields = import.schema_fields attributes = {} schema_fields.each do |field| attributes[field[:name]] = attribute_by_schema_field(field[:name], mappings) end attributes end end |
#update_footer_in_import_view ⇒ Object
93 94 95 96 97 |
# File 'app/models/spree/import_row.rb', line 93 def return unless defined?(broadcast_replace_to) broadcast_replace_to "import_#{import_id}_footer", target: 'footer', partial: 'spree/admin/imports/footer', locals: { import: import } end |