Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added phone formatting to immport. Some better error checking. Skippi…

…ng header row
  • Loading branch information...
commit 124232c162e7ffe5debe6c2e51c018b7573bd354 1 parent cc6bd16
Michael Bianco iloveitaly authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/tasks/import.rake
16 lib/tasks/import.rake
View
@@ -1,3 +1,7 @@
+# for phone number formatting
+require 'action_view/helpers'
+extend ActionView::Helpers
+
namespace :spree_retailers do
desc "Import list of retailers from a CSV"
task :import => :environment do |t, args|
@@ -44,7 +48,7 @@ namespace :spree_retailers do
:logo
]
- rows.each do |row|
+ rows[1..-1].each do |row|
info = {}
cols.each do |key, value|
@@ -52,6 +56,16 @@ namespace :spree_retailers do
row[value].try :strip!
info[key] = row[value] if valid_fields.include? key.to_sym
end
+
+ if info[:state].empty? or info[:zipcode].empty?
+ puts "Error adding #{info[:name]}, no state or zipcode defined"
+ next
+ end
+
+ # format phone number if applicable
+ unless info[:phone].empty?
+ info[:phone] = number_to_phone info[:phone], :area_code => true
+ end
# default to US
unless info.has_key? :country
Please sign in to comment.
Something went wrong with that request. Please try again.