class BBMB::Util::ProductImporter
Constants
- PRODUCT_MAP
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/bbmb/util/csv_importer.rb, line 80 def initialize super @active_products = {} end
Public Instance Methods
import_record(record)
click to toggle source
# File lib/bbmb/util/csv_importer.rb, line 84 def import_record(record) article_number = string(record[0]) return unless(/^\d+$/.match(article_number)) @active_products.store article_number, true product = Model::Product.find_by_article_number(article_number) \ || Model::Product.new(article_number) PRODUCT_MAP.each { |idx, name| value = string(record[idx]) writer = "#{name}=" case name when :description_de product.description.de = value when :description_fr product.description.fr = value else product.send(writer, value) end } product end
postprocess(persistence)
click to toggle source
# File lib/bbmb/util/csv_importer.rb, line 104 def postprocess(persistence) return if(@active_products.empty?) deletables = [] persistence.all(BBMB::Model::Product) { |product| unless(@active_products.include?(product.article_number)) deletables.push product end } persistence.all(BBMB::Model::Customer) { |customer| [customer.current_order, customer.favorites].each { |order| deletables.each { |product| order.add(0, product) } } } persistence.delete(*deletables) unless(deletables.empty?) end