7

We have following category and sub-category in our store.

Category: http://yoursite.com/category.html

Sub-category: http://yoursite.com/category/sub-category.html

Is it possible to access sub-category listing page using below URL

Sub-category: http://yoursite.com/sub-category.html

Case 1 : Access sub-category listing page, even if its main category id disabled

Case 2: Access sub-category listing page without using main category in URL

Also if my product is assigned to any sub-category and set the visibility to Catalog, will it appear on sub-category listing page when its category id disabled ?

How can I achieve this ?

Thanks

2

In Admin:

Admin -> System -> Config -> Catalog -> Search Engine Optimizations -> Use Parent Category Path for Category URLs (set to NO)

Programmatically:

Open the class Mage_Catalog_Model_Url and comment the below line

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

under function getCategoryRequestPath($category, $parentPath)

You can always create a local of your file, just in order to avoid over riding the core files

  • 1
    in magento ce Use Parent Category Path for Category URLs option is not there – Visakh B Sujathan Apr 21 '17 at 4:25
2

we made this extension to do it

https://github.com/seansan/snh_settings_CategoryParentUrl

Up+1 if you like it

0

i can recommend you to try below default function

Remove parent category path from url and change it from

http://mysite.com/category/sub-category.html to http://mysite.com/sub-category.html

USAGE :

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://mysite.com/category/sub-category.html

Option NO => http://mysite.com/sub-category.html

Edit

    <global>
        <models>
             <catalog>
                <rewrite>
                    <product_url>YourNamespace_Catalog_Model_Product_Url</product_url>
                </rewrite>
            </catalog>
        </models>
   </global>

you can try to rewrite url for category. hope this could be work for you. i am not 100% sure about this modle url rewrite in magento1.7

Hope this will sure help you.

  • Liyakat is right. – Amit Bera Jun 26 '14 at 7:24
  • @liyakat, Use Categories Path for Product URLs set to yes. Can not see the option you said i.e. 'Use Parent Category Path for Category URLs'. Version is 1.7.0.2 – Lazar Jun 26 '14 at 12:32
  • What should I do if I see no such option in my Mage admin ? – Lazar Jun 27 '14 at 4:31
  • @Lazar, see my updated answer. And you can necessary changes in URL model of catalog – liyakat Jun 27 '14 at 4:40
  • Where is this setting? (cannot find it in Magento 1.8.1) – snh_nl Aug 25 '14 at 15:04
0

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 = '';
//}

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.