0

Working on magento 1.9 (CE) website.

i have many categories and sub-categories but that makes url too long can i modify the same as below, if yes can anyone please help.

Below is the category tree Saree -> By Fabric -> Chiffon

current url : https://www.i-ranu.com/sarees-for-womens/by-fabric/chiffon-sarees-for-womens

i want to make url of all urls : https://www.i-ranu.com/chiffon-sarees-for-womens

0

If your magento version is not latest

Go to the Magento Admin Panel -> System -> Configuration -> Catalog -> Seo Options

Select yes or no from "Use Parent Category Path for Category URLs"

Refresh category url index

Option YES => http://www.example.com/category/subcategory.html

Option NO => http://www.example.com/subcategory.html

Programatically Solution :-

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 = '';
        //}
  • i tried to change the codes as per this but still am facing the same problem. please help – RANU EMPRISE May 21 '18 at 20:39
  • what kind of error you have facing ? – Yogesh May 22 '18 at 4:11
  • am not facing any error, i changed the same as provided and refreshed and cleared the cahe but still am unable to remove the subcategary path – RANU EMPRISE May 22 '18 at 17:33

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.