1

I try to create categories with the following code in a data-upgrade script. The categories where stored in the database but the seo-urls are not working.

Instead of {HOST}/categoryA/categoryB the url is like {HOST}/catalog/category/view/s/categorB/id/152/

/** @var Mage_Catalog_Model_Category $rootCat */
$rootCat = Mage::getModel('catalog/category');
$rootCat->setPath('1/3')
    ->setIsActive('1')
    ->setName('foobar')
    ->save();


/** @var Mage_Catalog_Model_Category */
$category = Mage::getModel('catalog/category');
$category->setPath($rootCat->getPath())
$category->setName($page->getData('title'));
$category->setMetaTitle($page->getData('pagetitle'));
$category->setIsActive(1);
$category->setIncludeInMenu(1);
$category->setDisplayMode('PRODUCTS_AND_PAGE');
$category->setIsAnchor(0);
$category->setPageLayout($page->getData('root_template'));
$category->setMetaKeywords($page->getData('meta_keywords'));
$category->setMetaDescription($page->getData('meta_description'));
$category->setColor($page->getData('color'));
$category->setBackground($page->getData('background'));
$category->save();

Any ideas?

Thanks in advance!

  • 1
    Did you tried reindexing? – mbalparda Oct 17 '14 at 13:41
  • are you sure all the URL rewrite modules are activated? (Apache and Magento) – Julien Lachal Oct 17 '14 at 14:00
  • @mbalparda It works after reindexing. Why is it necessary? – chmoelders Oct 17 '14 at 14:58
  • The reindex process updates the URLs as far as i know. I added an answer to this, please mark it as accepted so we can resolve this question. – mbalparda Oct 17 '14 at 15:45
0

After inserting the category reindex the indexes and that should fix your issue. You can add a reindex to your code also.

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.