autotelik / datashift

Full Excel/CSV Import/Export facilities for Rails
http://www.autotelik.co.uk
Other
136 stars 75 forks source link

How to attach Images to product? #6

Closed itsNikolay closed 12 years ago

itsNikolay commented 12 years ago

Sorry for noobish question. But. how to attach images to product ? I have file myapp/db/datashift/SpreeProductsWithImages.csv which I've copied from https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProductsWithImages.csv

And folder with images, myapp/db/datashift/fixtures/images tooked from there https://github.com/autotelik/datashift/tree/master/spec/fixtures/images

I run: $> bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv There I get products which migrated right but with no images.

DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images"]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 5, name: "mime_type", presentation: "Mime type", created_at: "2012-07-08 22:32:08", updated_at: "2012-07-08 22:32:08", position: 0>
Created missing OptionType #<Spree::OptionType id: 6, name: "print_type", presentation: "Print type", created_at: "2012-07-08 22:32:09", updated_at: "2012-07-08 22:32:09", position: 0>

Then i run $> bundle exec thor datashift:spree:images -i db/datashift/fixtures/images

So, how to upload images using specs tamplates ? In which folder images must be located and what's way to declare to each image? Thanks for awesome gem and your work!

autotelik commented 12 years ago

Hi  .. no probs

I have been doing alot of work on Images recently, and am about to push a new version to rubygems, socan I just ask .. are you having issues with the gem version or latest from github ?

thanks tom


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Sunday, 8 July 2012, 23:51 Subject: [datashift] How to attach Images to product. (#6)

Sorry for noobish question. But. how to attach images to product ? I have file myapp/db/datashift/SpreeProductsWithImages.csv  which I've copied from https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProductsWithImages.csv

And folder with images, myapp/db/datashift/fixtures/images tooked from there https://github.com/autotelik/datashift/tree/master/spec/fixtures/images

I run: $> bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv There I get products which migrated right but with no images.

DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images"]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 5, name: "mime_type", presentation: "Mime type", created_at: "2012-07-08 22:32:08", updated_at: "2012-07-08 22:32:08", position: 0>
Created missing OptionType #<Spree::OptionType id: 6, name: "print_type", presentation: "Print type", created_at: "2012-07-08 22:32:09", updated_at: "2012-07-08 22:32:09", position: 0>

Then i run $> bundle exec thor  datashift:spree:images -i db/datashift/fixtures/images

So, how to upload images using specs tamplates ? In which folder images must be located and what's way to declare to each image? Thanks for awesome gem and your work!


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6

itsNikolay commented 12 years ago

my Gemfile

gem 'rails', '3.2.3'
gem 'spree', '1.1.0'
gem 'datashift', '0.7.0'

Probaply, I have not correct located files ? And addition question: Do Products and Images import run with 2 different rake commands?

autotelik commented 12 years ago

hi

sorry probably my fault, I may have posted some suggestions that relate only to latest version

in 1.1.xx .. the Spree devs moved Images from association on Product, to an association on Variant which required a few rewrites

I have been working on this over the weekend and this morning, pushes changes so please try from github 

you should get a thor task with much more functionality ... basically it will progressively split and scan an image filename for a matching product Name or SKU. You can set the char to split on

So you could have images names like  sku1_blah.jpg or blah_blah_sku1.jpg  or 'blah more sku1.jpg'

You can try practice runs by specify -d. Will report what images where matched and what im,ages could not be matched to a Product

thor help datashift:spree:images  Usage:   thor datashift:spree:images -i, --input=INPUT

Options:   -i, --input=INPUT                                   # The import file (.xls or .csv)   -f, [--process-when-no-assoc]             # Process image even if no Product found - force loading   -s, [--sku=SKU]                                    # Lookup Product based on image name starting with sku   -p, [--sku-prefix=SKU_PREFIX]           # Prefix to add to each SKU in import file   -d, [--dummy]                                       # Dummy run, do not actually save Image or Product   -v, [--verbose]                                       # Verbose logging   -c, [--config=CONFIG]                          # Configuration file for Image Loader in YAML       [--split-file-name-on=SPLIT_FILE_NAMEON]  # delimiter to progressivley split filename for Prod lookup                                                                                   # Default:       [--case-sensitive]                         # Use case sensitive where clause to find Product       [--use-like]                               # Use LIKE 'string%' instead of = 'string' in where clauses

Populate the DB with images from a directory where image names map to Product Sku/Name


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Monday, 9 July 2012, 9:56 Subject: Re: [datashift] How to attach Images to product? (#6)

my Gemfile

gem 'rails', '3.2.3'
gem 'spree', '1.1.0'
gem 'datashift', '0.7.0'

Probaply, I have not correct located files ?


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6#issuecomment-6841603

itsNikolay commented 12 years ago

All files I tooked from sprecs. images located in mysite/db/datashift/fixtures/DEMO_001_ror_bag.jpeg and etc.

https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProducts.csv $>bundle exec thor datashift:spree:products -i db/datashift/SpreeProducts.csv


DataShift::Product starting upload from file: db/datashift/SpreeProducts.csv

Loading from CSV file: db/datashift/SpreeProducts.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 9, name: "mime_type", presentation: "Mime type", created_at: "2012-07-09 11:17:39", updated_at: "2012-07-09 11:17:39", position: 0>
Created missing OptionType #<Spree::OptionType id: 10, name: "print_type", presentation: "Print type", created_at: "2012-07-09 11:17:39", updated_at: "2012-07-09 11:17:39", position: 0>

https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeImages.xls $>bundle exec thor datashift:spree:images -i db/datashift/SpreeImages.xls -d


Using Product Name for lookup
CONFIG: {}
ERROR: Supplied Path db/datashift/SpreeImages.xls not accesible

What's wrong =) ? Probably I didn't install jruby?

autotelik commented 12 years ago

$>bundle exec thor datashift:spree:images -i db/datashift/SpreeImages.xls -d

This task is for bulk uploading a directory of images so -i is expected to be a Path

So command would be something like

bundle exec thor datashift:spree:images -i mysite/db/datashift/fixtures/images -d

For an example file, of loading images alongside Products in one go see....

https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProductsWithImages.csv

here each image path is set in the csv file column  Images

If you copy that to your project db/datahsift area as per below cmd would be something like

bundle exec thor datashift:spree:products -i db/datashift//SpreeProductsWithImages.csv

Jruby only required if you want to process .xls files, CSV works regardless

Cheers tom


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Monday, 9 July 2012, 12:27 Subject: Re: [datashift] How to attach Images to product? (#6)

All files I tooked from sprecs. images located in mysite/db/datashift/fixtures/DEMO_001_ror_bag.jpeg  and etc.

https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProducts.csv $>bundle exec thor datashift:spree:products -i db/datashift/SpreeProducts.csv


DataShift::Product starting upload from file: db/datashift/SpreeProducts.csv

Loading from CSV file: db/datashift/SpreeProducts.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 9, name: "mime_type", presentation: "Mime type", created_at: "2012-07-09 11:17:39", updated_at: "2012-07-09 11:17:39", position: 0>
Created missing OptionType #<Spree::OptionType id: 10, name: "print_type", presentation: "Print type", created_at: "2012-07-09 11:17:39", updated_at: "2012-07-09 11:17:39", position: 0>

https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeImages.xls $>bundle exec thor datashift:spree:images -i db/datashift/SpreeImages.xls -d


Using Product Name for lookup
CONFIG: {}
ERROR: Supplied Path db/datashift/SpreeImages.xls not accesible

What's wrong =) ? Probably I didn't install jruby?


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6#issuecomment-6844081

itsNikolay commented 12 years ago

bundle exec thor datashift:spree:images -i db/datashift/fixtures/images -s

Using SKU for lookup
CONFIG: {}

No effect.

bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv

DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images"]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows

Probably i don;t have right locations with images ?


Uploaded with ImageShack.us

When will be gem realise to check new functionslity with Spree 1.1.0 ?

autotelik commented 12 years ago

all specs passing with

gem 'rails', '3.2.3' gem 'spree', '1.1.1'

if you do

ls  db/datashift/fixtures/images

what files are in there ?

might be quicker if you explain what you are trying to do and I can point you to right task

cheers tom


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Monday, 9 July 2012, 13:03 Subject: Re: [datashift] How to attach Images to product? (#6)

bundle exec thor  datashift:spree:images -i db/datashift/fixtures/images -s

Using SKU for lookup
CONFIG: {}

No effect.

bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv

DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images"]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows

Probably i don;t have right locations with images ?


Uploaded with ImageShack.us


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6#issuecomment-6844646

itsNikolay commented 12 years ago

It would be nice. I just want https://github.com/autotelik/datashift/blob/master/spec/fixtures/spree/SpreeProductsWithImages.csv make work. But i get just products import, images don't want to be imported. So questions are: Where i should store .csv file? Where i should store folder with images? What's name of images should be (plz give me example of name for)? What should i execute in command line to import all of this ?

Probably you can upload folder with this working files. I think that i make mistake somewhere with names. Or i don't know what i do wrong.

autotelik commented 12 years ago

Ok so if you look in that CSV file it defines a relative path to each image .. as fixtures/images/xxxx.jpg

So copy the CSV file up to the datashift directory, so from there 'ls fixtures/images' should list the images indicating relative path correct, then this should work :

bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv

Alternatively but more work, edit the CSV file to change the path to each image match your setup.

When loading alongside Products from csv/xls in this way, the actual name of images is irrelevant, only that the path to them is valid - relative to wherever you are running thor

The alternative task datashift:spree:images is for bulk loading a directory of Images against a set of Products that have already been loaded. In this case the filename is very important and must contain either the SKU or Name of the product to attach to.

autotelik commented 12 years ago

sorry just seen your screenshot with dirs

copy both the CSV file and the fixtures folder up one to the datashift directory

paths to images are relative to wherever you are running thor

itsNikolay commented 12 years ago

$>bundle exec thor datashift:spreeboot:cleanup && bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv

Clearing model Spree::Image
Clearing model Spree::OptionType
Clearing model Spree::OptionValue
Clearing model Spree::Product
Clearing model Spree::Property
WARNING - Coulod not find AR model for class name ProductGroup
Clearing model Spree::ProductProperty
Clearing model Spree::ProductOptionType
Clearing model Spree::Variant
Clearing model Spree::Taxonomy
Clearing model Spree::Taxon
Clearing model Spree::Zone
Removing old Product assets from 'public/spree/products'
DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images                                                                                                          "]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 13, name: "mime_type", presentation: "Mime type", created_at: "2012-07-09 12:57:06", updated_at: "2012-07-09 12:57:06", position: 0>
Created missing OptionType #<Spree::OptionType id: 14, name: "print_type", presentation: "Print type", created_at: "2012-07-09 12:57:07", updated_at: "2012-07-09 12:57:07", position: 0>

What's strange error WARNING? Probably 'Images' should have different name ? (database's table has name 'spree_assets')

Also 'fixtures/images' in root directory of my app.


Uploaded with ImageShack.us

Database records for spree_variants and spree_assets:

autotelik commented 12 years ago

Hi .. yes this is an Warning issue introduced by Spree  moving Images from Product to Variant

I have pushed 0.8.0 to rubygems which fixes this warning

I have copied your setup so from rails.root  

csv is in  db/datashift images in  fixtures/images/

ls fixtures/images/     DEMO_001_ror_bag.jpeg  DEMO_002_Powerstation.jpg  DEMO_003_ror_mug.jpeg  DEMO_004_ror_ringer.jpeg

Now running gives ...

DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv Processing 3 rows Created missing OptionType #<Spree::OptionType id: 3, name: "mime_type", presentation: "Mime type", created_at: "2012-07-09 13:35:02", updated_at: "2012-07-09 13:35:02", position: 0> Add Image fixtures/images/DEMO_001_ror_bag.jpeg Success: Created Image: 1903 : DEMO_001_ror_bag.jpeg Add Image fixtures/images/DEMO_002_Powerstation.jpg Success: Created Image: 1904 : DEMO_002_Powerstation.jpg Created missing OptionType #<Spree::OptionType id: 4, name: "print_type", presentation: "Print type", created_at: "2012-07-09 13:35:09", updated_at: "2012-07-09 13:35:09", position: 0> Add Image fixtures/images/DEMO_003_ror_mug.jpeg Success: Created Image: 1905 : DEMO_003_ror_mug.jpeg


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Monday, 9 July 2012, 14:15 Subject: Re: [datashift] How to attach Images to product? (#6)

$>bundle exec thor datashift:spreeboot:cleanup && bundle exec thor datashift:spree:products -i db/datashift/SpreeProductsWithImages.csv

Clearing model Spree::Image
Clearing model Spree::OptionType
Clearing model Spree::OptionValue
Clearing model Spree::Product
Clearing model Spree::Property
WARNING - Coulod not find AR model for class name ProductGroup
Clearing model Spree::ProductProperty
Clearing model Spree::ProductOptionType
Clearing model Spree::Variant
Clearing model Spree::Taxonomy
Clearing model Spree::Taxon
Clearing model Spree::Zone
Removing old Product assets from 'public/spree/products'
DataShift::Product starting upload from file: db/datashift/SpreeProductsWithImages.csv
WARNING: Following column headings could not be mapped : ["Images                                                                                                          "]

Loading from CSV file: db/datashift/SpreeProductsWithImages.csv
Processing 3 rows
Created missing OptionType #<Spree::OptionType id: 13, name: "mime_type", presentation: "Mime type", created_at: "2012-07-09 12:57:06", updated_at: "2012-07-09 12:57:06", position: 0>
Created missing OptionType #<Spree::OptionType id: 14, name: "print_type", presentation: "Print type", created_at: "2012-07-09 12:57:07", updated_at: "2012-07-09 12:57:07", position: 0>

What's strange error WARNING? Probably 'Images' should have different name ? (database's table has name 'spree_assets')

Also 'fixtures/images' in root directory of my app.


Uploaded with ImageShack.us

Database records for spree_variants and spree_assets:


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6#issuecomment-6846055

itsNikolay commented 12 years ago

Works like a charm! Thanks for awesome gem. And your time spending to maintrace it!

autotelik commented 12 years ago

ok cool, glad we got there

all the best with your project


From: Ponomarev Nikolay reply@reply.github.com To: tom statter github@autotelik.co.uk Sent: Monday, 9 July 2012, 15:35 Subject: Re: [datashift] How to attach Images to product? (#6)

Works like a charm! Thanks for awesome gem.


Reply to this email directly or view it on GitHub: https://github.com/autotelik/datashift/issues/6#issuecomment-6848145