Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't attach images on product update #64

Open
LucaDev13 opened this issue Sep 13, 2017 · 5 comments
Open

can't attach images on product update #64

LucaDev13 opened this issue Sep 13, 2017 · 5 comments

Comments

@LucaDev13
Copy link

LucaDev13 commented Sep 13, 2017

gemfile:
ruby '2.3.0'
gem 'rails', '4.2.5'
gem 'spree', '~> 3.1.0'
gem 'datashift', github: 'autotelik/datashift'
gem 'datashift_spree', github: 'autotelik/datashift_spree', :branch => 'feature/update_api_latest_ds_and_spree'

I can't attach images during Product creation. I've added the image field and attempted with both url for the file or full path. Running thor datashift_spree:load:products -i filepath.xls does create the product but the image is now.

When instead trying to add the image to existing products with thor datashift_spree:load:attach_images -i filepath.xls I get the following argument error complaint. The spreadsheet uses a sku and an attachment

bundler/gems/datashift_spree-8fb9c3ae017a/lib/loaders/spree/image_loader.rb:26:in `initialize': wrong number of arguments (given 2, expected 0) (ArgumentError)

thor datashift:paperclip:attach -a Spree::Image -k Spree::Variant -f images --attach-to-find-by-field=sku -i filepath.xls --split_file_name_on _
returns

WARNING : 1 of 1 files could not be attached to a Spree::Image For your convenience copying files with MISSING Spree::Variant to : MissingAttachmentRecords Created 0 / 1 attachments of type Spree::Image attached to Spree::Variant
with this log output

D, [2017-09-13T23:57:01.101313 #21725] DEBUG -- : Catalogue - building operators information for Spree::Variant
I, [2017-09-13T23:57:01.117192 #21725]  INFO -- : Loading attachments from vendor/datashift/templates/product_images.xls
I, [2017-09-13T23:57:01.145786 #21725]  INFO -- : Loading objects of type Spree::Image
I, [2017-09-13T23:57:01.145842 #21725]  INFO -- : Found 1 files - splitting names on delimiter [_]
I, [2017-09-13T23:57:01.145863 #21725]  INFO -- : Finding matching field/association [images] on class [Spree::Variant]
D, [2017-09-13T23:57:01.146041 #21725] DEBUG -- : Column [images] (0) - mapped to :
      Class         [Spree::Variant]
      Operator Type [has_many]
      Operator      [images]

I, [2017-09-13T23:57:01.146065 #21725]  INFO -- : Processing attachment file product_images.xls 
I, [2017-09-13T23:57:01.146091 #21725]  INFO -- : Attempting to find attachment owner (Spree::Variant for [product_images]
I, [2017-09-13T23:57:01.146107 #21725]  INFO -- : Scanning for record where Spree::Variant.sku ~=  product_images
D, [2017-09-13T23:57:01.147343 #21725] DEBUG -- :   �[1m�[35mSpree::Variant Load (0.2ms)�[0m  SELECT  "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'product_images')  ORDER BY "spree_variants"."id" ASC LIMIT 1
I, [2017-09-13T23:57:01.147466 #21725]  INFO -- : Nothing found - trying split file_name to terms on [_]
I, [2017-09-13T23:57:01.147486 #21725]  INFO -- : Scanning by term for record where sku ~=  product
D, [2017-09-13T23:57:01.147903 #21725] DEBUG -- :   �[1m�[36mSpree::Variant Load (0.1ms)�[0m  �[1mSELECT  "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'product')  ORDER BY "spree_variants"."id" ASC LIMIT 1�[0m
I, [2017-09-13T23:57:01.147974 #21725]  INFO -- : Scanning by term for record where sku ~=  images
D, [2017-09-13T23:57:01.148372 #21725] DEBUG -- :   �[1m�[35mSpree::Variant Load (0.1ms)�[0m  SELECT  "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'images')  ORDER BY "spree_variants"."id" ASC LIMIT 1
D, [2017-09-13T23:57:01.148815 #21725] DEBUG -- :   �[1m�[36mSpree::Variant Load (0.1ms)�[0m  �[1mSELECT  "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = '_product')  ORDER BY "spree_variants"."id" ASC LIMIT 1�[0m
D, [2017-09-13T23:57:01.149262 #21725] DEBUG -- :   �[1m�[35mSpree::Variant Load (0.1ms)�[0m  SELECT  "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'product_images')  ORDER BY "spree_variants"."id" ASC LIMIT 1
E, [2017-09-13T23:57:01.149351 #21725] ERROR -- : Failure(s) reported :
E, [2017-09-13T23:57:01.149369 #21725] ERROR -- : 	No matching owner found for file name : product_images
I, [2017-09-13T23:57:01.149417 #21725]  INFO -- : Copying vendor/datashift/templates/product_images.xls to MissingAttachmentRecords folder
@autotelik
Copy link
Owner

Hi ... sorry I do not work commercially with Spree at present so I think the gem is lagging behind the Spree data model but the bulk attach of images should work

It looks like it could not match the value in teh SKU field to a product

No matching owner found for file name : product_images

Could you share the images spreadsheet ? or just a couple of rows with the headers ?

@LucaDev13
Copy link
Author

Hi and thanks!

The images spreadsheet can be represented as below. I can confirm that both sku values are present in the back-office.


sku attachment
ABCD /home/Downloads/coming-soon.jpg
EFGHI /home/Downloads/coming-soon.jpg

Please let me know if I can provide more information on this.

@LucaDev13
Copy link
Author

I further tested and was eventually able to upload a new product by adding an images field in the spreadsheet.

However the problem persists when trying to update a product

thor datashift:paperclip:attach --attachment-klass=Spree::Image --attach-to-field=images --input=vendor/datashift/templates/product_images.xls --attach-to-klass=Spree::Variant --attach-to-find-by-field=sku

returns
Using Field sku to lookup matching [Spree::Variant] Logging going to target [log/datashift.log] WARNING : 1 of 1 files could not be attached to a Spree::Image For your convenience copying files with MISSING Spree::Variant to : MissingAttachmentRecords Created 0 / 1 attachments of type Spree::Image attached to Spree::Variant

logfile

`
D, [2017-09-17T12:59:11.268485 #21262] DEBUG -- : Catalogue - building operators information for Spree::Variant
I, [2017-09-17T12:59:11.284418 #21262] INFO -- : Loading attachments from vendor/datashift/templates/product_images.xls
I, [2017-09-17T12:59:11.313654 #21262] INFO -- : Loading objects of type Spree::Image
I, [2017-09-17T12:59:11.313711 #21262] INFO -- : Found 1 files - splitting names on delimiter [ ]
I, [2017-09-17T12:59:11.313734 #21262] INFO -- : Finding matching field/association [images] on class [Spree::Variant]
D, [2017-09-17T12:59:11.313915 #21262] DEBUG -- : Column [images] (0) - mapped to :
Class [Spree::Variant]
Operator Type [has_many]
Operator [images]

I, [2017-09-17T12:59:11.313939 #21262] INFO -- : Processing attachment file product_images.xls
I, [2017-09-17T12:59:11.313957 #21262] INFO -- : Attempting to find attachment owner (Spree::Variant for [product_images]
I, [2017-09-17T12:59:11.313972 #21262] INFO -- : Scanning for record where Spree::Variant.sku ~= product_images
D, [2017-09-17T12:59:11.315256 #21262] DEBUG -- : �[1m�[35mSpree::Variant Load (0.2ms)�[0m SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'product_images') ORDER BY "spree_variants"."id" ASC LIMIT 1
I, [2017-09-17T12:59:11.315372 #21262] INFO -- : Nothing found - trying split file_name to terms on [ ]
I, [2017-09-17T12:59:11.315392 #21262] INFO -- : Scanning by term for record where sku ~= product_images
D, [2017-09-17T12:59:11.315811 #21262] DEBUG -- : �[1m�[36mSpree::Variant Load (0.1ms)�[0m �[1mSELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = 'product_images') ORDER BY "spree_variants"."id" ASC LIMIT 1�[0m
D, [2017-09-17T12:59:11.316255 #21262] DEBUG -- : �[1m�[35mSpree::Variant Load (0.1ms)�[0m SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."deleted_at" IS NULL AND (lower(sku) = ' product_images') ORDER BY "spree_variants"."id" ASC LIMIT 1
E, [2017-09-17T12:59:11.316353 #21262] ERROR -- : Failure(s) reported :
E, [2017-09-17T12:59:11.316371 #21262] ERROR -- : No matching owner found for file name : product_images
I, [2017-09-17T12:59:11.316429 #21262] INFO -- : Copying vendor/datashift/templates/product_images.xls to MissingAttachmentRecords folder
`

@LucaDev13 LucaDev13 changed the title can't attach images - product creation and product update can't attach images on product update Sep 17, 2017
@autotelik
Copy link
Owner

Ahhh I see the issue now, misunderstanding of use case - this Task is not driven by a spreadsheet

It's for a different use case, bulk uploading based on file names

Create paperclip attachments and attach to a Model from files in a directory.

-i, --input=INPUT # The input path containing images

The file name is used to lookup the instance of :attach_to_klass to assign the new attachment to

So the filenames should contain the SKU (somewhere) so these would work

e.g ABCD.jpg or coming_soon_ABCD.jpg or ABCD_coming_soon.jpg etc

So currently its treating vendor/datashift/templates/product_images.xls as the input image

I think you want -i /home/Downloads/

@LucaDev13
Copy link
Author

Ok thanks! I will give a try to this method as you have mentioned.

Regarding spreadsheet usage is this syntax correct? thor datashift_spree:load:attach_images --input=vendor/datashift/templates/product_images.xls. This still returns an ArgumentError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants