Forum

Thread tagged as: Api, Shop

Perch Shop import - assets not imported

Hi,

When importing using the following code, no asset is attached to the product:

$Importer->add_item([ 'sku' => slugify($title), 'title' => $title, 'slug' => slugify($title), 'description' => $content, 'image_assetID' => 1786, 'price' => ['gbp' => 0], 'on_sale' => false, 'status' => true, 'requires_shipping' => true, 'tax_group' => 1, 'stock_status' => '1', ]);

Running latest Runway and Shop apps. The asset is a valid asset ID also.

Perch Runway: 3.0.14, PHP: 7.1.8, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO Server OS: Darwin, apache2handler Installed apps: content (3.0.14), assets (3.0.14), categories (3.0.14), perch_blog (5.6.1), perch_forms (1.9), perch_shop_orders (1.2.5), perch_shop_products (1.2.5), perch_shop (1.2.5), perch_members (1.6.2) App runtimes: <?php $apps_list = [ 'perch_members', 'perch_shop', 'perch_forms', 'perch_blog' ]; PERCH_LOGINPATH: /admin PERCH_PATH: /Users/ryangittings/Builds/client/admin PERCH_CORE: /Users/ryangittings/Builds/client/admin/core PERCH_RESFILEPATH: /Users/ryangittings/Builds/client/admin/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 32M, Memory: 256M, Total max file upload: 32M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes HTTP_HOST: client.local DOCUMENT_ROOT: /Users/ryangittings/Builds/client REQUEST_URI: /admin/core/settings/diagnostics/ SCRIPT_NAME: /admin/core/settings/diagnostics/index.php

Thanks, Ryan.

Ryan Gittings

Ryan Gittings 1 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you adding the asset? Is there a field called image in your template?

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

I'm using the Asset Importer but tried using a static ID for testing purposes.

$imageAsset = $AssetImporter->add_item([ 'type' => 'image', 'bucket' => 'default', 'path' => $directory ]);

The asset imports perfectly, I get my ID and then pass to the Shop importer, but no dice.

Yeah the image field is in my product template, like so:

<perch:shop id="image" type="image" label="Image" width="600" height="400" crop="true" order="4" help="1200 x 800px" /> <perch:shop id="image" type="image" label="Image" width="600" height="400" crop="true" density="2" />

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you checked the debug?

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Yeah, no obvious errors there. The INSERT INTO perch3_shop_products has no mention of image whatsoever.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Could you show me an example of it?

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Of the insert sql?

INSERT INTO perch3_shop_products(title,sku,productDynamicFields,productCreated) VALUES('Black Basalt','black-basalt','{\"description\":{\"_flang\":\"markdown\",\"raw\":\"6mm and 14mm.\",\"processed\":\"<p>6mm and 14mm.<\\/p>\"},\"slug\":\"black-basalt\",\"status\":\"1\",\"category\":[\"12\"],\"price\":{\"47\":0,\"_default\":0},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"requires_shipping\":\"1\"}','2018-02-09 10:20:15')

Drew McLellan

Drew McLellan 2638 points
Perch Support

And the context, yes.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

It's a PHP script that just imports from a scraper, from the client's old site. I've validated all the data and that the asset uploads and imports okay. It's just that it doesn't seem to get applied to the product.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you please show me the debug output? This would be so much easier.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Debug Message - Perch Runway 3.0.14
[1] SELECT * FROM perch3_pages WHERE pagePath='/admin/addons/apps/rg_importer/import.php' LIMIT 1
[41] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
Using template: /templates/shop/products/product.html
Resizing image... (gd, w150 h150 @2x thumb)
INSERT IGNORE INTO perch3_resources(resourceApp,resourceBucket,resourceFile,resourceKey,resourceParentID,resourceType,resourceCreated,resourceInLibrary,resourceFileSize,resourceWidth,resourceHeight,resourceMimeType,resourceTitle) VALUES('rg_importer','default','black-basalt-87.jpg','orig',0,'jpg','2018-02-09 15:56:16','0',48075,300,300,'image/jpeg','Black basalt')
INSERT IGNORE INTO perch3_resources(resourceApp,resourceBucket,resourceFile,resourceKey,resourceParentID,resourceType,resourceCreated,resourceInLibrary,resourceWidth,resourceHeight,resourceTargetWidth,resourceTargetHeight,resourceDensity,resourceFileSize,resourceMimeType,resourceTitle) VALUES('rg_importer','default','black-basalt-87-thumb@2x.jpg','thumb','2110','jpg','2018-02-09 15:56:16','0',150,150,150,150,2,56422,'image/jpeg','Black basalt')
[1] SELECT * FROM perch3_shop_products WHERE sku='black-basalt' AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch3_categories WHERE catPath='products/building/aggregates/' LIMIT 1
[1] SELECT * FROM perch3_shop_currencies WHERE currencyActive=1 ORDER BY currencyID=47 DESC, currencyCode
[1] SELECT * FROM perch3_shop_currencies WHERE currencyActive=1 ORDER BY currencyID=47 DESC, currencyCode
INSERT INTO perch3_shop_products(title,sku,productDynamicFields,productCreated) VALUES('Black Basalt','black-basalt','{\"description\":{\"_flang\":\"markdown\",\"raw\":\"6mm and 14mm.\",\"processed\":\"<p>6mm and 14mm.<\\/p>\"},\"slug\":\"black-basalt\",\"status\":\"1\",\"category\":[\"12\"],\"price\":{\"47\":0,\"_default\":0},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"requires_shipping\":\"1\"}','2018-02-09 15:56:16')
[1] SELECT * FROM perch3_shop_products WHERE productID='477' LIMIT 1
Logging resources for rg_importer
DELETE FROM perch3_resource_log WHERE appID='rg_importer' AND itemFK='productID' AND itemRowID=477
INSERT IGNORE INTO perch3_resource_log(`appID`, `itemFK`, `itemRowID`, `resourceID`) VALUES('rg_importer','productID',477,2110),('rg_importer','productID',477,2111)
UPDATE perch3_shop_products SET title='Black Basalt', sku='black-basalt', productDynamicFields='{\"description\":{\"_flang\":\"markdown\",\"raw\":\"6mm and 14mm.\",\"processed\":\"<p>6mm and 14mm.<\\/p>\"},\"slug\":\"black-basalt\",\"status\":\"1\",\"category\":[\"12\"],\"price\":{\"47\":0,\"_default\":0},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"requires_shipping\":\"1\"}', productCreated='2018-02-09 15:56:16', productSlug='black-basalt', productStatus='1', productUpdated='2018-02-09 15:56:16' WHERE productID='477'
No ids to log.
UPDATE perch3_shop_products SET title='Black Basalt', sku='black-basalt', productDynamicFields='{\"description\":{\"_flang\":\"markdown\",\"raw\":\"6mm and 14mm.\",\"processed\":\"<p>6mm and 14mm.<\\/p>\"},\"slug\":\"black-basalt\",\"status\":\"1\",\"category\":[\"12\"],\"price\":{\"47\":0,\"_default\":0},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"requires_shipping\":\"1\"}', productSlug='black-basalt', productStatus='1', productUpdated='2018-02-09 15:56:16' WHERE productID='477'
No ids to log.
Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Also to note, the product doesn't get indexed but that's a separate issue.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try this:

'image' => '',
'image_assetID' => 1786,
Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Perfect! Worked a charm.

Thanks Drew!