1

I'm trying to assign a product to a number of categories programmatically. I'm using this code to do so :

$arrayofCategories = array($Id1,$Id2);
$product->setCategoryIds($arrayofCategories);

Note that i'm using that same $product to set others attributes and they were set properly but when i check the product in backend in its categories section, none of the categories with the ids in the array is checked.

Is this the right syntax ?

2

Yes it seems to be the right syntax, but keep in mind that if you don't merge new IDs with olders it override the olders one.
Take a look at this answer it may help you : https://stackoverflow.com/a/6512286/3531064

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.