문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top