Pregunta

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.

¿Fue útil?

Solución 2

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.

Otros consejos

Change "Use Categories Path for Product URLs" property in System -> Configuration -> Catalog to "No".

There is one simple way to do this for every where, copy Url.php from app\code\core\Mage\Catalog\Model\Product and past URl.php into app\code\local\Mage\Catalog\Model\Product. After that need to update getUrl function.

Find this line: $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null; and update with $categoryId = $product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories') ? $product->getCategoryId() : null;

Hope this will help someone.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top