Import products with images from CSV

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: Import products with images from CSV

Post by columbo » 23 Mar 2020, 15:27

I'm not sure if I got it right.
I process a csv file with new and updated products once a day (for csv example see comment from 18 Feb 2020, 12:43)
After the file is processed, images of the new or updated products are not displayed, images of already existing products are still displayed.

I now execute after each csv import:

Code: Select all

artisan aimeos:jobs media/scale
Then all images are displayed correctly.
It seems that this generates new images (thumbnails etc.) for all products, and not only for new or updated products.

Is this the recommended / correct way?
If not, how can I updated / import products with images correctly?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Import products with images from CSV

Post by aimeos » 01 Apr 2020, 07:36

Normally, preview images should be automatically generated on import:
https://github.com/aimeos/ai-controller ... #L172-L185

If this is not the case in your situation, please have a look at into the source code why that happens. Simply add a few debug statements at the code block to see which if/else branch is used. Then, we can see if it's a bug or if your CSV file contains something it shouldn't.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: Import products with images from CSV

Post by columbo » 15 Apr 2020, 11:17

following if/else branch is used
https://github.com/aimeos/ai-controller ... #L176-L177

I also attached an example of the csv file:
Attachments
productupdate.zip
(585 Bytes) Downloaded 170 times

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Import products with images from CSV

Post by aimeos » 15 Apr 2020, 11:20

What's your mapping configuration?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: Import products with images from CSV

Post by columbo » 15 Apr 2020, 11:46

mapping:

Code: Select all

'mapping' => [
	'item' => array(
		1 => 'product.code', // e.g. unique EAN code					
		3 => 'product.label', // UTF-8 encoded text, also used as product name
		2 => 'product.type', // type of the product, e.g. "default" or "selection"
		9 => 'product.status', // enabled (1) or disabled (0)
	),
	'text' => array(
		4 => 'text.type', // e.g. "short" for short description
		5 => 'text.content', // UTF-8 encoded text								
	),
	'media' => array(
		39 => 'media.url', // relative URL of the product image on the server
		//40 => 'media.type',
		//42 => 'media.label',
		//43 => 'product.lists.type',
	),
	'price' => array(
		14 => 'product.lists.type',

		7 => 'price.taxrate', // tax rate with decimals separated by a dot
		16 => 'price.currencyid', // three letter ISO currency code
		17 => 'price.value', // price with decimals separated by a dot
		18 => 'price.quantity', // amount the quantity the price (for block pricing)
		20 => 'product.lists.datestart',
		21 => 'product.lists.dateend',
	
		41 => 'price.taxrate',
		23 => 'price.currencyid', // three letter ISO currency code
		24 => 'price.value', // price_1
		25 => 'price.quantity', // amount_1
		26 => 'product.lists.datestart', // valid_from_1
		27 => 'product.lists.dateend', // valid_to_1

		28 => 'price.currencyid', // three letter ISO currency code
		29 => 'price.value', // price_1
		30 => 'price.quantity', // amount_1
		31 => 'product.lists.datestart', // valid_from_1
		32 => 'product.lists.dateend', // valid_to_1
		
		33 => 'price.currencyid', // three letter ISO currency code
		34 => 'price.value', // price_1
		35 => 'price.quantity', // amount_1
		36 => 'product.lists.datestart', // valid_from_1
		37 => 'product.lists.dateend', // valid_to_1		
	),
	'attribute' => array(
		12 => 'product.lists.type', // e.g. "suggestion" for suggested product  attributeproductlist = variant 
		10 => 'attribute.code', // code of an attribute, will be created if not exists
		11 => 'attribute.type', // e.g. "size", "length", "width", "color", etc.
		
		//44 => 'product.lists.type', // e.g. "suggestion" for suggested product  attributeproductlist = variant 
		45 => 'attribute.code', // code of an attribute, will be created if not exists
		46 => 'attribute.type', // e.g. "size", "length", "width", "color", etc.
	),
	'product' => array(
		15 => 'product.code', // e.g. EAN code of another product
		22 => 'product.lists.type', // e.g. "suggestion" for suggested product
	),

	'catalog' => array(
		8 => 'catalog.code', // e.g. Unique category code
		38 => 'catalog.code', // e.g. Unique category code
		// 20 => 'catalog.lists.type', // e.g. "promotion" for top seller products
	),
	'stock' => array(
		13 => 'stock.stocklevel',
	),
]

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Import products with images from CSV

Post by aimeos » 15 Apr 2020, 17:25

Strange, media preview isn't defined in your mapping. Can you check what's returned here:
https://github.com/aimeos/ai-controller ... d.php#L140
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: Import products with images from CSV

Post by columbo » 16 Apr 2020, 07:10

I added $context->getLogger()->log after L140

when using:
$context->getLogger()->log( 'preview 1: ' . $this->getValue( $list, 'media.preview', '' ));
empty, just prints: "preview 1: "

when using:
$context->getLogger()->log( 'preview 2: ' . $preview);
causes an error: "Unable to import product with code "123456": Array to string conversion"

when using:
$context->getLogger()->log( 'preview 3: ' . $separator);
empty, just prints: "preview 3: "

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Import products with images from CSV

Post by aimeos » 16 Apr 2020, 08:16

OK, think we've found the problem:
explode( "\n", '' ) returns array( 0 => '' ) and therefore, the if/elseif/else thinks a preview path is available. We've added an additional check and now it should move on to the branch for creating the previews.

Can you please run

Code: Select all

composer req aimeos/ai-controller-jobs:2019.10.x-dev
and test again?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: Import products with images from CSV

Post by columbo » 16 Apr 2020, 16:49

unfortunately, its still not working.
now none of the three if/else branches from https://github.com/aimeos/ai-controller ... #L174-L180 are used

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Import products with images from CSV

Post by aimeos » 16 Apr 2020, 17:04

For existing products where you haven't change the URL, that's intentional because of:
https://github.com/aimeos/ai-controller ... d.php#L178

Try with new products or new URLs.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply