简体   繁体   中英

PHP module does not set quantity for prestashop

Hi I am using php module to add a new product. Everything works great but this code for some reason does not set the quantity of product.

$id_product = (int)Db::getInstance()->getValue("SELECT id_product FROM `$product` WHERE reference = '$product_xml[id]'");
$p = new Product();
$p->reference = $product_xml['id'];
$p->price = (float)$price;
$p->active = 1;
$p->quantity = (int)$product_xml['count']; 
$p->minimal_quantity = 1;
$p->available_for_order=1;
$p->id_category = array(26);
$p->id_category_default = 26;
$p->name[1] = $product_xml['name'];
$p->description[1] = utf8_encode($product_xml->Description);
$p->description_short[1] = utf8_encode($product_xml->Short_Description);
$p->link_rewrite[1] = Tools::link_rewrite($product_xml['name']);
if (!isset($p->date_add) || empty($p->date_add))
$p->date_add = date('Y-m-d H:i:s');
$p->date_upd = date('Y-m-d H:i:s');
$p->save();
$id_product ? $p->updateCategories(array(26)) : $p->addToCategories(array(26));

You should also use:

StockAvailable::setQuantity($p->id, null, (int)$product_xml['count']);

Put that after your current code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM