Magento getting a products rewritten URL
If you look at this thread; http://www.magentocommerce.com/boards/viewthread/10807/
It adds a products rewritten url to the collection using;
$collection->addUrlRewrite($categoryId);
I am not getting products this 开发者_JS百科way, I am using this method to get an individual product:
$product->load($productId);
After quite a bit of searching I cant seem to figure a way of getting a products rewritten url using this method, can anyone tell me how I may go about this please?
Thanks
I'm not quite sure whether "rewritten url" means request_path
or target_path
in your question context, but anyway.
To get the request path of a single product you can do this:
$oProduct = Mage::getModel('catalog/product')->load($productId);
var_dump(
$oProduct->getUrlPath()
);
To get the target path, you can use this:
$oProduct = Mage::getModel('catalog/product')->load($productId);
$oRewrite = Mage::getModel('core/url_rewrite')->loadByRequestPath(
$oProduct->getUrlPath()
);
var_dump(
$oRewrite->getTargetPath()
);
精彩评论