【问题标题】:Magento: Get product id by urlMagento:通过 url 获取产品 id
【发布时间】:2017-03-30 12:33:49
【问题描述】:

例如这里是url

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

有几种简单的产品。如何从这个 url 获取实际的简单产品 ID?

Magento 1.8

【问题讨论】:

    标签: php magento-1.8


    【解决方案1】:

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

    【讨论】:

    • 我们如何在 magento 2 中得到它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多