0

I want to remove parent category in listing page

i tried this Programmatically But it won't work:

Open the class Mage_Catalog_Model_Url and comment the below line

//if (null === $parentPath) {
//    $parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == '/') {
    $parentPath = '';
//}

this is my url http://domain.com/baby-care/baby-body-care-products-online/baby-cream-perfumes-oils-lotions-for-skin.html

but i want http://totaltoys.com/baby-cream-perfumes-oils-lotions-for-skin.html

How I achieve this?

2 Answers 2

0

To remove category paths from product url set "Use Categories Path for Product URLs" to "No" under System -> Configuration -> Catalog -> Search Engine Optimizations.

To remove parent category path from child category url
Rewrite class Mage_Catalog_Model_Url
override method public function getCategoryRequestPath($category, $parentPath) like below

public function getCategoryRequestPath($category, $parentPath)
    {
        $storeId = $category->getStoreId();
        $idPath  = $this->generatePath('id', null, $category);
        $suffix  = $this->getCategoryUrlSuffix($storeId);

        if (isset($this->_rewrites[$idPath])) {
            $this->_rewrite = $this->_rewrites[$idPath];
            $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
        }

        if ($category->getUrlKey() == '') {
            $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
        }
        else {
            $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
        }

        $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
        // Code commented to remove parent category path from child category path
        //if (null === $parentPath) {
            //$parentPath = $this->getResource()->getCategoryParentPath($category);
        //}
        //elseif ($parentPath == '/') {
            $parentPath = '';
        //}
        $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath,
                                                                           true, $category->getStoreId());

        $requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
        if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) {
            return $existingRequestPath;
        }

        if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) {
            return $requestPath;
        }

        return $this->getUnusedPath($category->getStoreId(), $requestPath,
                                    $this->generatePath('id', null, $category)
        );
    }


Modified below code

if (null === $parentPath) {
            $parentPath = $this->getResource()->getCategoryParentPath($category);
        }
        elseif ($parentPath == '/') {
            $parentPath = '';
        }

to

//if (null === $parentPath) {
            //$parentPath = $this->getResource()->getCategoryParentPath($category);
        //}
        //elseif ($parentPath == '/') {
            $parentPath = '';
        //}
1
  • i already done but it's not working
    – Magento 2
    Commented Nov 19, 2015 at 12:43
0

Go to System > Configuration > Catalog > Search Engine Optimizations find Use Categories Path for Product URLs and make this as No and save it and make index managment and check the urls

3
  • i already done but it's not working
    – Magento 2
    Commented Nov 19, 2015 at 12:43
  • u did index management also ? Commented Nov 19, 2015 at 12:44
  • No luck i already did it
    – Magento 2
    Commented Nov 19, 2015 at 12:51

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.