shopmaster export from aliexpress to csv for spree_datashift import

238 views
Skip to first unread message

fugee ohu

unread,
Jun 11, 2018, 4:56:30 AM6/11/18
to Ruby on Rails: Talk
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

Hassan Schroeder

unread,
Jun 11, 2018, 8:19:12 AM6/11/18
to rubyonrails-talk
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.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

fugee ohu

unread,
Jun 11, 2018, 11:30:33 AM6/11/18
to Ruby on Rails: Talk
I'm looking for a more spree specific answer 

fugee ohu

unread,
Jun 11, 2018, 4:11:54 PM6/11/18
to Ruby on Rails: Talk


On Monday, June 11, 2018 at 8:19:12 AM UTC-4, Hassan Schroeder wrote:
Write my own importer using thor or without?

Hassan Schroeder

unread,
Jun 11, 2018, 4:46:04 PM6/11/18
to rubyonrails-talk
On Mon, Jun 11, 2018 at 1:11 PM, fugee ohu <fuge...@gmail.com> wrote:

> 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`?

qwan

unread,
Jun 12, 2018, 4:47:04 AM6/12/18
to Ruby on Rails: Talk
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 

qwan

unread,
Jun 12, 2018, 4:49:58 AM6/12/18
to Ruby on Rails: Talk
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)
 

qwan

unread,
Jun 12, 2018, 5:00:58 AM6/12/18
to Ruby on Rails: Talk
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

fugee ohu

unread,
Jun 12, 2018, 3:40:51 PM6/12/18
to Ruby on Rails: Talk
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

 

fugee ohu

unread,
Jun 15, 2018, 8:42:51 AM6/15/18
to Ruby on Rails: Talk
How would I do that?
 
Reply all
Reply to author
Forward
0 new messages