Skip to content

Instantly share code, notes, and snippets.

@kimmellj
Created September 18, 2015 14:31
Show Gist options
  • Save kimmellj/f8b8791a44ae508c834f to your computer and use it in GitHub Desktop.
Save kimmellj/f8b8791a44ae508c834f to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'csv'
xmlString = '<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://www.demandware.com/xml/impex/catalog/2006-10-31" catalog-id="nautica-master-catalog">
'
batch = ARGV[0]
puts "Working with #{batch}"
i = 0
CSV.foreach("./#{batch}.csv") do |row|
if i == 0
i += 1
next
end
xmlString += "
<product product-id=\"#{row[1]}\">
<custom-attributes>
<custom-attribute attribute-id=\"svReadyId\">#{row[0]}</custom-attribute>
<custom-attribute attribute-id=\"svSearchable\">true</custom-attribute>
<custom-attribute attribute-id=\"svType\">sv_stitch</custom-attribute>
</custom-attributes>
<options>
<shared-option option-id=\"stitch_text\"/>
</options>
</product>
"
i += 1
end
xmlString += '
</catalog>
'
filename = DateTime.now.strftime('%Y-%m-%d-%H-%M') + "monogramming-fix-#{batch}.xml"
File.open(filename, 'w') do |f2|
f2.puts xmlString
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment