CptSilver Posted November 5, 2014 Share Posted November 5, 2014 Hello, I have see some posts about creating a product or about the category so a copied the code and now have this : $defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT'))); /* Add a new product */ $object = new Product(); $object->price = 32; $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)); $object->save(); So, my product is created with all info BUT the category. When i test the data of addToCategories he do that test 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 for me $new_id_categ is in $current_categories, so the thing never add it. Anyone have an idea? Thanks Link to comment Share on other sites More sharing options...
CptSilver Posted November 6, 2014 Author Share Posted November 6, 2014 Nobody? Link to comment Share on other sites More sharing options...
CptSilver Posted November 6, 2014 Author Share Posted November 6, 2014 It's solved : addToCategories does only work on a already existing product, so you need to use the save() before. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now