Welcome to the THELIA support and discusssion forum


Rejoignez la communauté sur le Discord Thelia :


After importing a Thelia 1 database to a Thelia 2.2.1 platform,
I've been trying to apply a php script to do some cleaning.

Especially, I've been trying to move the products from the imported categories to new ones.

The products are removed from the old category, I can see that in the backoffice,
but the new category is still empty. Apparently something is missing in my script.

basically, what I do is :


      $productCategories = $product->getProductCategories();


Does anybody would have an idea about what I'm missing ?

thanks for the help,
loïc b.

Last edited by neywen (04-01-2016 15:33:02)


Is $productCategories[0] containing the expected (e.g., new one) category ?

Try to save the category changes befor requesting category list :


$productCategories = $product->getProductCategories();

OpenStudio Toulouse


Thanks for your message,

I've enumerated the ProductCategory objects from the collection,
and I can see that it contains both the old one and the new one :

my logs :

// log : move product 20 from category 11 to category 35


$productCategories = $product->getProductCategories();
foreach ($productCategories as $productCategory) {
    echo "enumerated productCategory ".$productCategory->getCategoryId()."\n";

// log :
// enumerated productCategory 11
// enumerated productCategory 35

Does it mean that the removeCategory call did not properly worked ?

[EDIT] : I just saw your edit. I'm going to try now.

Last edited by neywen (04-01-2016 15:53:06)


It does not change anything.
Both old and new categories are still enumerated when I call getProductCategories().

I'm going to try to set a new product categories collection.

      $collection = new \Propel\Runtime\Collection\Collection();

Yep. Saving the product after add/removeCategory and setting a new ProductCategories collection does the expected job.
Thank you for your help.

I'm just concerned about why the old category is still enumerated after calling removeCategory. If removeCategory is not supposed to dynamically update the productCategories collection, then that's ok, it's the appropriate behavior. otherwise, it might indicate another problem somewhere, and then, my "$productCategories[1]->setDefaultCategory(1)" is a bit hacky. But it's good enough for what I need to do.

Thanks !
loïc b.

Last edited by neywen (04-01-2016 16:05:17)