Jump to content

Can not link product to a category with php script


lolrich

Recommended Posts

Hello,

 

I am using the inbuild import system, to import all my products,

but i can't find a way to link the products to my existing/new categories,

 

i am using this:

$object->id_category_default = 12;

$object->category[] = 12;

 

and the category id 12 already exists and works fine,

and the product is created fine, its only the relation from the product to the category that is missing,

 

i hope there is someone out there who got the magic moves to solve this issue :-)

 

been searching everyone without any luck!

 

Regards

Link to comment
Share on other sites

Assuming that you have an array of categories that the product belongs to I would set it via:

 

$cats = array('1', '2', '3');
$product->id_category_default = $cats[0];
$product->updateCategories($cats);

 

If you only have 1 category to set (12 in your example) then just do:

 

$product->id_category_default = 12;
$product->updateCategories(array('12'));

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...