Forum
Products Imported into Shop Not Showing on Front End Until Saved
I have a product Importer that is almost working:
$API = new PerchAPI(1.0, 'my_importer');
$Importer = $API->get('PerchShopProductImporter');
//Open the file.
$fileHandle = fopen("/pathto/testData.csv", "r");
while (($row = fgetcsv($fileHandle, 0, ",")) !== FALSE) {
try {
$Importer->add_item([
'sku' => $row[0],
'title' => $row[1],
'slug' => $row[2],
'description' => $row[3],
'status' => true,
'brand' => 1,
'catalog_only' => false,
'price' => ['gbp' => 10, 'eur'=>12, 'usd'=>13],
'sale_price' => ['gbp' => 8, 'eur'=>10, 'usd'=>11],
'trade_price' => ['gbp' => 7, 'eur'=>9, 'usd'=>10],
'on_sale' => false,
'tax_group' => 1,
'stock_status' => '1',
'stock_level' => '199',
'stock_location' => true,
'max_in_cart' => 10,
'requires_shipping' => true,
'weight' => 100,
'width' => 20,
'height' => 15,
'depth' => 30,
'productStatus' => 1,
]);
} catch (Exception $e) {
die('Error: '.$e->getMessage());
}
}
Currently I'm only testing, so I'm only importing the first 4 rows of data, and hard coding the remainder. Debug shows the results as follows:
Debug Message - Perch Runway 3.0.14
[13] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch3_pages p LEFT JOIN perch3_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch3_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch3_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
Matched pageless route: productImport
Using master page: /templates/pages/shop/productImport.php
Page arguments:
Array
(
[0] => /productImport
)
[1] SELECT * FROM perch3_shop_cart WHERE cartID=1
[1] SELECT * FROM perch3_shop_cart WHERE cartID=1
[nil] SELECT * FROM perch3_shop_sales WHERE saleFrom<='2018-02-03 12:24:00' AND saleTo>'2018-02-03 12:24:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
[31] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
Using template: /templates/shop/products/product.html
[1] SELECT * FROM perch3_shop_products WHERE 1=1 AND productDeleted IS NULL ORDER BY title ASC
UPDATE perch3_shop_products SET productDeleted='2018-02-03 12:24:53', productUpdated='2018-02-03 12:24:53' WHERE productID='519'
No ids to log.
[1] SELECT * FROM perch3_shop_products WHERE sku='5014' AND productDeleted IS NULL 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
[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
[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,stock_level,productDynamicFields,productCreated) VALUES('SampleProduct 14','5014','199','{\"description\":{\"_flang\":\"markdown\",\"raw\":\"This the the sample product 14\",\"processed\":\"<p>This the the sample product 14<\\/p>\"},\"slug\":\"sample-product-14\",\"status\":\"1\",\"brand\":1,\"catalog_only\":\"\",\"price\":{\"47\":10,\"_default\":10},\"sale_price\":{\"47\":8,\"_default\":8},\"trade_price\":{\"47\":7,\"_default\":7},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"stock_location\":\"1\",\"max_in_cart\":\"10\",\"requires_shipping\":\"1\",\"weight\":\"100\",\"width\":\"20\",\"height\":\"15\",\"depth\":\"30\"}','2018-02-03 12:24:53')
[1] SELECT * FROM perch3_shop_products WHERE productID='520' LIMIT 1
No ids to log.
UPDATE perch3_shop_products SET title='SampleProduct 14', sku='5014', stock_level='199', productDynamicFields='{\"description\":{\"_flang\":\"markdown\",\"raw\":\"This the the sample product 14\",\"processed\":\"<p>This the the sample product 14<\\/p>\"},\"slug\":\"sample-product-14\",\"status\":\"1\",\"brand\":1,\"catalog_only\":\"\",\"price\":{\"47\":10,\"_default\":10},\"sale_price\":{\"47\":8,\"_default\":8},\"trade_price\":{\"47\":7,\"_default\":7},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"stock_location\":\"1\",\"max_in_cart\":\"10\",\"requires_shipping\":\"1\",\"weight\":\"100\",\"width\":\"20\",\"height\":\"15\",\"depth\":\"30\"}', productCreated='2018-02-03 12:24:53', productStockOnParent='1', productSlug='sample-product-14', productStatus='1', productUpdated='2018-02-03 12:24:53' WHERE productID='520'
No ids to log.
UPDATE perch3_shop_products SET title='SampleProduct 14', sku='5014', stock_level='199', productDynamicFields='{\"description\":{\"_flang\":\"markdown\",\"raw\":\"This the the sample product 14\",\"processed\":\"<p>This the the sample product 14<\\/p>\"},\"slug\":\"sample-product-14\",\"status\":\"1\",\"brand\":1,\"catalog_only\":\"\",\"price\":{\"47\":10,\"_default\":10},\"sale_price\":{\"47\":8,\"_default\":8},\"trade_price\":{\"47\":7,\"_default\":7},\"on_sale\":\"\",\"tax_group\":1,\"stock_status\":\"1\",\"stock_location\":\"1\",\"max_in_cart\":\"10\",\"requires_shipping\":\"1\",\"weight\":\"100\",\"width\":\"20\",\"height\":\"15\",\"depth\":\"30\"}', productStockOnParent='1', productSlug='sample-product-14', productStatus='1', productUpdated='2018-02-03 12:24:53' WHERE productID='520'
No ids to log.
Request time: 0.4206
Process time: 0.3952
Memory: 4.5163
The script works fine and the product appear in the admin area. However until I open a product and save it it doesn't appear on the front end? When I open the product the status is showing as 'Active', however until I save the product it doesn't appear on the front end of the site.
Can anyone help?
I'm not 100% on what this script does but It appears the product data is being inserted into the 'perch3_shop_products' table, but the 'perch3_shop_index' table isn't updated until I save the product through the product editor admin screen.
Anyone?
That shouldn't be the case - the items should be indexed as far as I'm aware.
Hello Drew,
I'll do a screen recording and post the code of all the files involved. I'm not at the machine for a few hours now.
It's normally something simple I'm missing.
The products appear in the back end. When editing a product the status dropper is already set to active however until I save the product it doesn't appear in the front end product list.
I'm also seeing this - the products are imported but not indexed.