I’m trying to use shopmaster to export from aliexpress to csv for spree_datashift import Spree uses a separate table for prices I notice How am I supposed to do this? Thanks in advance
Your choices:
1. Write your own exporter 2. Write your own importer 3. Transform the original exported CSV into the required import format
Assuming the exporter and importer are both complex and mature (well-tested), #3 is generally the preferred approach.
I’m looking for a more spree specific answer
Write my own importer using thor or without?
I've never used thor; what are the pros and cons of using it vs. e.g. rake or `rails runner`?
Datashift has template generation for any active record model to csv or excel, for example to create a csv template for a Spree product :
thor datashift:generate:csv -m Spree::Product --result /tmp/spree_products.csv
``
You can also export the headers with data via datashift:export:csv
$ more /tmp/spree_products.csv
id,name,description,available_on,deleted_at,slug,meta_description,meta_keywords,tax_category_id,shipping_category_id,created_at,updated_at,promotionable,meta_title,discontinue_on
``
This gives the required columns into Spree. You can copy the data from your export into the correct Spree fields, the final file can then be imported via
thor datashift:import:csv -i /tmp/spree_products.csv -m Spree::Product
``
N.B Spree data model and requirements are complex, simple import may not be enough, you may need to write a few helpers or extend datashift:import, the README and Wiki are quite extensive
cheers
tom
p.s The excel template generation is a bit more advanced e.g does not include Rails cols like id, created_at by default
$ th datashift:generate:excel
Usage:
thor datashift:generate:excel -m, --model=MODEL -r, --result=RESULT
Options:
-m, --model=MODEL # The active record model to export
-r, --result=RESULT # Create template of model in supplied file
[–include-rails=INCLUDE_RAILS] # Include Rails auto generated columns like :id, created_at, updated_at
-f, [–force=one two three] # Inform datashift of columns that are still call-able even though they’re non model methods
-a, [–associations], [–no-associations] # Include associations. Can be further refined by :with & :exclude
[–expand-associations], [–no-expand-associations] # Expand association data to multiple columns i.e 1 column per attribute
generate a template from an active record model (with optional associations)
thor is a good drop in replacement for rake for CLIs - for me I much prefer it’s argument/option definition and parsing, and it’s a bit easier to organise and invoke scripts as they are PORO
for me, rake is good for build orientated tasks, thor for everything else
This is the spree products tables structures Everything’s spread out across different tables
create_table “spree_prices”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.integer “variant_id”, null: false
t.decimal “amount”, precision: 10, scale: 2
t.string “currency”
t.datetime “deleted_at”
t.index [“deleted_at”], name: “index_spree_prices_on_deleted_at”, using: :btree
t.index [“variant_id”, “currency”], name: “index_spree_prices_on_variant_id_and_currency”, using: :btree
t.index [“variant_id”], name: “index_spree_prices_on_variant_id”, using: :btree
end
create_table “spree_product_option_types”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.integer “position”
t.integer “product_id”
t.integer “option_type_id”
t.datetime “created_at”, null: false
t.datetime “updated_at”, null: false
t.index [“option_type_id”], name: “index_spree_product_option_types_on_option_type_id”, using: :btree
t.index [“position”], name: “index_spree_product_option_types_on_position”, using: :btree
t.index [“product_id”], name: “index_spree_product_option_types_on_product_id”, using: :btree
end
create_table “spree_product_promotion_rules”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.integer “product_id”
t.integer “promotion_rule_id”
t.index [“product_id”], name: “index_products_promotion_rules_on_product_id”, using: :btree
t.index [“promotion_rule_id”, “product_id”], name: “index_products_promotion_rules_on_promotion_rule_and_product”, using: :btree
end
create_table “spree_product_properties”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.string “value”
t.integer “product_id”
t.integer “property_id”
t.datetime “created_at”, null: false
t.datetime “updated_at”, null: false
t.integer “position”, default: 0
t.index [“position”], name: “index_spree_product_properties_on_position”, using: :btree
t.index [“product_id”], name: “index_product_properties_on_product_id”, using: :btree
t.index [“property_id”], name: “index_spree_product_properties_on_property_id”, using: :btree
end
create_table “spree_products”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.string “name”, default: “”, null: false
t.text “description”, limit: 65535
t.datetime “available_on”
t.datetime “discontinue_on”
t.datetime “deleted_at”
t.string “slug”
t.text “meta_description”, limit: 65535
t.string “meta_keywords”
t.integer “tax_category_id”
t.integer “shipping_category_id”
t.datetime “created_at”, null: false
t.datetime “updated_at”, null: false
t.boolean “promotionable”, default: true
t.string “meta_title”
t.index [“available_on”], name: “index_spree_products_on_available_on”, using: :btree
t.index [“deleted_at”], name: “index_spree_products_on_deleted_at”, using: :btree
t.index [“discontinue_on”], name: “index_spree_products_on_discontinue_on”, using: :btree
t.index [“name”], name: “index_spree_products_on_name”, using: :btree
t.index [“shipping_category_id”], name: “index_spree_products_on_shipping_category_id”, using: :btree
t.index [“slug”], name: “index_spree_products_on_slug”, unique: true, using: :btree
t.index [“tax_category_id”], name: “index_spree_products_on_tax_category_id”, using: :btree
end
create_table “spree_products_taxons”, force: :cascade, options: “ENGINE=InnoDB DEFAULT CHARSET=latin1” do |t|
t.integer “product_id”
t.integer “taxon_id”
t.integer “position”
t.index [“position”], name: “index_spree_products_taxons_on_position”, using: :btree
t.index [“product_id”], name: “index_spree_products_taxons_on_product_id”, using: :btree
t.index [“taxon_id”], name: “index_spree_products_taxons_on_taxon_id”, using: :btree
end
“You can copy the data from your export into the correct Spree fields” How would I do that?