Search code examples
phpmagentomagento-1.5

Force Magento to use only one URL in all listings


My problem is the following: Magento creates URL rewrites for new products and uses different URLs on different listings. If my product is in two categories Foo and Bar, Magento will use two URLs on top of the one I actually want.

  • In category listing Foo => /store/type/foo/product.html
  • In category listing Bar => /store/type/bar/product.html
  • In normal linking /store/product.html

I want/need to get Magento to use only the URL /store/product.html throughout the entire store. I have not found any setting in the admin pages for that.

Using Magento 1.5.1.0.


Solution

  • For some reason, Magento ignored the setting for all the stores. After searching the code, I found that the method Mage_Catalog_Model_Product_Url::getUrl() checks this setting with $product->getDoNotUseCategoryId(). I called this method, and it returned NULL for all the products.

    To solve this, I overloaded this method in my own product class:

    public function getDoNotUseCategoryId(){
        return true;
    }
    

    This works.

    It might be a problem with a non-existent attribute or something, but as long as this works I'll use it.