Gefferey Zhang
Gefferey Zhang

Reputation: 95

magento getProductUrl does not include category path

does getProductUrl return product url with the category path, how can i get it to work like that, it seems others will suggest to use a helper, but i guess it is not the only way.

Upvotes: 2

Views: 3094

Answers (2)

Pimpreneil
Pimpreneil

Reputation: 61

The proposed answer did not work on my Magento version (1.9).

Here is what worked for me:

$category = Mage::getModel('catalog/category')->load($categorieId);
Mage::unregister('current_category');
Mage::register('current_category', $category);
$product->getProductUrl();

Upvotes: 1

Michael Leiss
Michael Leiss

Reputation: 5660

I haven't checked it but I am quite sure the product needs to know about the category.

$product->setCategoryId($categoryId)->getProductUrl();

Upvotes: 2

Related Questions