I am having problems trying to release some xml import for my store through an object $product. When I try to fill the $productparticipants, everything works fine, all the loops all over. 800 products that I have in my xml. But when I add the save method at the end of the loop, it only accepts the first 10 products and never does.
I tried to sleep(1)post after $product->save(), as I thought SQL was dropping the connection due to high-income queries, but that didn't help anything.
Do you guys know why this is happening? Below is my code (I am not inserting the xml file here, as I think it is not important).
Work with Prestashop 1.6.0.9.
<?
include('../config/config.inc.php');
include('../init.php');
if (file_exists('exportgoods.xml'))
{
$xml = simplexml_load_file('exportgoods.xml');
foreach ($xml->PRODUCTS->PRODUCT as $jmena_produktu)
{
if($jmena_produktu->PRODUCER == "2"):
$reference=$string = str_replace(' ', '', $jmena_produktu->NAME);
$id_product = (int)Db::getInstance()->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.pSQL($reference).'\'');
$product = $id_product ? new Product((int)$id_product, true) : new Product();
$product->reference = $reference;
$product->price = (float)$jmena_produktu->PRICEWITHDPH;
$product->id_category_default = 2;
$product->category = 15;
$product->name[1] = (string)$jmena_produktu->NAME;
$product->description[1] = (string)$jmena_produktu->LONGDESCRIPTION;
$product->description_short[1] = (string)$jmena_produktu->DESCRIPTION;
$product->link_rewrite[1] = Tools::link_rewrite($reference);
if (!isset($product->date_add) || empty($product->date_add))
$product->date_add = date('Y-m-d H:i:s');
$product->date_upd = date('Y-m-d H:i:s');
$id_product ? $product->updateCategories(array(2,15)) : $product->addToCategories(array(2,15));
$product->save();
echo 'Product <b>'.$product->name[1].'</b> '.($id_product ? 'updated' : 'created').'<br />';
endif;
}
}
else
{
exit('Failed to open exportgoods.xml.');
}
?>