簡體   English   中英

Magento:通過URL獲取產品ID

[英]Magento: Get product id by url

例如,這是網址

http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-ls-93368.html

有幾種簡單的產品。 如何從該URL獲取實際的簡單產品ID?

Magento的1.8

首先,使用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);

然后,您可以在路線上調用getProductId()來找到產品ID:

$iProductId = $oRewrite->getProductId();

最后,如果您需要產品模型對象本身,則可以很簡單地調用:

$oProduct = Mage::getModel('catalog/product')->load($iProductId);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM