0

I create category:

 $category->setName(self::CATEGORY_AZ_NAME)
            ->setUrlKey('...')
            ->setUrlPath('...')
            ->setIsActive(1)
            ->setDisplayMode(Mage_Catalog_Model_Category::DM_PRODUCT)
            ->setIsAnchor(0)
            ->setStoreId(0)
            ->setPath($rootCategory->getPath())
            ->setAttributeSetId($category->getDefaultAttributeSetId())
            ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
            ->setInitialSetupFag(true)
            ->save();

But on a front this category have wrong link. I think that there are URL rewrite not created.

How can i create URL REWRITE for this category?

3
  • Did you check the rewrite table if it was added? And did you reindex after running this script? Commented Feb 25, 2015 at 16:23
  • yes you are right, i see it in "URL Rewrite Management" -this all OK. And i add code $reindex = array('catalog_category_product', 'catalog_url'); foreach ($reindex as $index) { Mage::getModel('index/indexer')->getProcessByCode($index)->reindexAll(); } But in front for this category URL = catalog/category/view/
    – Ratio
    Commented Feb 25, 2015 at 16:35
  • @Ratio, so you solved the problem yourself? Then would you please add your solution as an answer (answer your own question)
    – 7ochem
    Commented Feb 27, 2015 at 16:00

2 Answers 2

1

You forgot to set the parent id.
Also you don't need to set the url_path. It will be calculated.
So your script should look like this:

$category->setName(self::CATEGORY_AZ_NAME)
        ->setUrlKey('...')
        ->setIsActive(1)
        ->setDisplayMode(Mage_Catalog_Model_Category::DM_PRODUCT)
        ->setIsAnchor(0)
        ->setStoreId(0)
        ->setParentId($rootCategory->getId())
        ->setPath($rootCategory->getPath())
        ->setAttributeSetId($category->getDefaultAttributeSetId())
        ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
        ->setInitialSetupFag(true)
        ->save();

Also I think setInitialSetupFag has no effect.

1
  • How to do with Default URL Rewrite Management for Main Category, Is Possible?
    – zus
    Commented Mar 23, 2018 at 12:22
0

I suggest you dont use the Url management magento default functionality.I had used below link for category redirect

http://magento.ikantam.com/qa/custom-redirect-category-page-magento

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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