Add new product in PrestaShop by core development

No comments
hello the below code is to add new product in PrestaShop



                                $p = new Product;
$p->name = Tools::getValue('name');
$p->id_category_default = Tools::getValue('category');
$p->indexed = 1;
$p->active = Tools::getValue('active');
$p->redirect_type = '404';
$p->visibility = 'both';
$p->id_supplier = 0;
$p->reference = strtolower(Tools::getValue('name'));
// $p->link_rewrite = array(
// 1 => strtolower(Tools::getValue('name')),
// 2 => strtolower(Tools::getValue('name')),
// ); // link rewrite must be array with every uses languages
//$product->minimal_quantity = 1;
//$product->show_price = 1;
$p->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => Tools::link_rewrite(Tools::getValue('name')));
$p->quantity = 1;
$p->price = Tools::getValue('price');
$p->description = Tools::getValue('Description');
$p->description_short = Tools::getValue('summary');
$p->id_sponser = $this->context->customer->id;
$p->date_add = date('Y-m-d H:i:s');
$p->date_upd = date('Y-m-d H:i:s');
$p->add();
$p->addToCategories(2,Tools::getValue('category'));

No comments :

Post a Comment