Class: BBMB::Util::CustomerImporter
- Inherits:
-
CsvImporter
- Object
- CsvImporter
- BBMB::Util::CustomerImporter
- Defined in:
- lib/bbmb/util/csv_importer.rb
Constant Summary collapse
- CUSTOMER_MAP =
{ 1 => :ean13, 3 => :title, 4 => :firstname, 5 => :lastname, 6 => :organisation, 8 => :address1, 9 => :plz, 10 => :city, 11 => :phone_business, 12 => :fax, }
Instance Method Summary collapse
Methods inherited from CsvImporter
#import, #postprocess, #string
Instance Method Details
#import_record(record) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bbmb/util/csv_importer.rb', line 50 def import_record(record) customer_id = string(record[0]) ean13 = string(record[1]) return unless(/^\d+$/.match(customer_id)) customer = Model::Customer.find_by_customer_id(customer_id) if customer.nil? && !ean13.to_s.empty? \ && (customer = Model::Customer.find_by_ean13(ean13) \ || Model::Customer.find_by_customer_id(ean13)) customer.customer_id = customer_id end customer ||= Model::Customer.new(customer_id) CUSTOMER_MAP.each { |idx, name| unless customer.protects? name customer.send("#{name}=", string(record[idx])) end } customer rescue Yus::DuplicateNameError => err @duplicates.push(err) nil end |