Skip to content

Instantly share code, notes, and snippets.

@gfmurphy
Created February 20, 2012 16:13
Show Gist options
  • Save gfmurphy/1869946 to your computer and use it in GitHub Desktop.
Save gfmurphy/1869946 to your computer and use it in GitHub Desktop.
Proposed Spree Data Import API
Spree::DataImport.for(:taxons).run("https://abcdef012356789:x@wherethedatalives.com/taxons.xml")
Spree::Taxonomy.class_eval do
data_import(:taxons) do |config|
config.source do
fields do
add(:id, :name, :description, :parent_id, :position, :icon)
decorate(:id) { |id| id.to_i }
decorate(:name) { |name| name.strip.titleize }
decorate(:description) do |description|
RDiscount.new(description.gsub(" | ", "\n\n").
gsub(/<\/?font[\s\w="]*>/, '').
gsub(/<\/?b>/, '').
gsub(/(\s|&nbsp;)+/, " ").
gsub(/(\*|&bull;)\s*/, "\n* ")).to_html
end
decorate(:parent_id) { |parent_id| parent_id.to_i }
decorate(:position) { |position| position.to_i }
end
xml! { |xml| xml.tag_name = "taxons" }
end
config.destination do
active_model! do |model|
model.key = :id
model.scope = Spree::Taxon.find_or_create_by_name('Categories').taxons
end
end
config.before_each do |taxon|
end
config.after_each do |taxon|
# taxon.image_update!
end
config.after_all do
#tax = Spree::Taxonomy.find_by_name('Categories')
#TaxonomyTree.new(tax).reposition_taxons!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment