PRESTASHOP 1.6 Add a category to a product programmatically -



PRESTASHOP 1.6 Add a category to a product programmatically -

in module clients can add together products shop, pass separate database. when admin check products , validate one, alter info prestashop product.

so have code :

$object = new product(); $object->price = 32; $object->id_tax_rules_group = 0; $object->name = array((int)configuration::get('ps_lang_default') => $creation['title']); $object->id_manufacturer = 0; $object->id_supplier = 0; $object->quantity = 1; $object->minimal_quantity = 1; $object->additional_shipping_cost = 0; $object->wholesale_price = 0; $object->ecotax = 0; $object->out_of_stock = 0; $object->available_for_order = 1; $object->show_price = 1; $object->on_sale = 1; $object->online_only = 1; $object->meta_keywords = $creation['title']; $object->active = 1; $object->description_short = array((int)(configuration::get('ps_lang_default')) => $creation['description']); $object->link_rewrite = array((int)(configuration::get('ps_lang_default')) => $creation['title']); $object->id_category = 2; $object->id_category_default = 2; $object->addtocategories(array(2,13)); //save $object->save()

the product saved , has info it's not associated category. when go page products, can see products, see product , category there when come in details of product , go category list nil check.

i tried see more in code happenning , saw :

if (!in_array($new_id_categ, $current_categories)) $product_cats[] = array( 'id_category' => (int)$new_id_categ, 'id_product' => (int)$this->id, 'position' => (int)$new_categ_pos[$new_id_categ], );

and after test "if" true , product association never created. have check , association not exist.

i don't know next, or if maybe need not utilize addtocategory, , come in maybe info myself...

so please help thanks.

the method addtocategories() assigns categories created product. in other words need phone call save() method of product class before calling addtocategories();

prestashop category product programmatically-created

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -