rendered paste body163 def import
164 @file_import = FileImport.new
165 if request.post?
166 #params['file_import']['data'] = params['file_import']['tmp_file'].read
167 #@params['file_import'].delete('tmp_file')
168 @file_import = FileImport.new(params[:file_import])
169 @file_import.client_id = @client.id
170 @new_products = Array.new
171 @good_products = Array.new
172 iterator = -1
173 #TODO: Match existing products
174 #TODO: Check content-type of file and perform preliminary analysis
175 CSV::Reader.parse(File.open(@file_import.file.to_s, 'rb')) do |row|
176 #Skip the header.
177 if iterator < 0
178 iterator += 1
179 else
180 @new_products << Product.new(:sku => row[0],
181 :name => row[1],
182 :product_status_code_id => '1',
183 :client_id => @client.id ) unless row[0].nil? or row[1].nil?
184 iterator += 1
185 end
186 #Now we have the length of the products array, we can probably do
187 #some fancy submit_to_remote progress bar hackery
188 @new_products.each {|product|
189 product.save!
190 }
191 end
192 end