Magento retrieves rewritten product URLs

If you look at this topic; http://www.magentocommerce.com/boards/viewthread/10807/

It adds products rewritten by url to the collection using;

$ gallery-> addUrlRewrite ($ CategoryId);

I do not receive such products, I use this method to get a separate product:

$ product-> load ($ PRODUCTID);

After a little searching, I cannot figure out how to get the product rewritten by the URL using this method, can someone tell me how I can do this?

thanks

+2
magento
source share
1 answer

I'm not quite sure that "rewritten URL" means request_path or target_path in the context of your question, but anyway.

To get the request path to 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() ); 
+6
source share

All Articles