[英]Magento: Get product id by url
For example, here is url 例如,这是网址
http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-ls-93368.html . http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-ls-93368.html 。
There are several simple products. 有几种简单的产品。 How can I get the actual simple product ID, from this url? 如何从该URL获取实际的简单产品ID?
Magento 1.8 Magento的1.8
First use the URL rewrite model to find the route which matches your product: 首先,使用URL重写模型来查找与您的产品匹配的路由:
$vPath = 'http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html';
$oRewrite = Mage::getModel('core/url_rewrite')
->setStoreId(Mage::app()->getStore()->getId())
->loadByRequestPath($vPath);
Then you can call getProductId() on the route to locate the produc's id: 然后,您可以在路线上调用getProductId()来找到产品ID:
$iProductId = $oRewrite->getProductId();
Finally if you require the product model object itself it's then a simple matter to call: 最后,如果您需要产品模型对象本身,则可以很简单地调用:
$oProduct = Mage::getModel('catalog/product')->load($iProductId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.