Question

I am using PHP to set up my categories in Magento 1.4.2

$categories[] = array('id' => '23', 'path' => '16');
$categories[] = array('id' => '24', 'path' => '16/23');
$categories[] = array('id' => '25', 'path' => '16/23/24');

foreach ($categories as $category) {   
    $current_category = Mage::getModel('catalog/category')
        ->load($category['id'])
        ->setPath('1/2/'.$category['path'])
        ->save();
}

However something has gone wrong

The categories have been imported like this:

root
-23
-16
--24

and 25 is nowhere to be seen

Have I got something wrong with my logic or how to use Mage::getModel('catalog/category') and ->setPath

Was it helpful?

Solution

I have fixed this. The path should include the category id too. Thanks to Eugene Tulika for the pointer in the right direction.

To confirm the $categories array I should have set up was

$categories[] = array('id' => '23', 'path' => '16/23');
$categories[] = array('id' => '24', 'path' => '16/23/24');
$categories[] = array('id' => '25', 'path' => '16/23/24/25');

Shame I couldn't find any documentation on what to pass to setPath() anywhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top