【问题标题】:How to show shipping costs per product in product page in Magento 1.9.1如何在 Magento 1.9.1 的产品页面中显示每个产品的运费
【发布时间】:2016-09-16 02:45:29
【问题描述】:

有没有办法在 Magento 1.9.1 的产品详细信息页面中显示产品成本? 我希望每个产品都显示相关的运费,非常感谢

【问题讨论】:

    标签: magento-1.9 shipping


    【解决方案1】:

    您可以将以下代码粘贴到主题中的“/template/catalog/product/view.phtml”文件中。

    if($_product->isSaleable())
    {
    $quote = Mage::getModel('sales/quote');
    $quote->getShippingAddress()->setCountryId('DK');
    $quote->addProduct($_product); 
    $quote->getShippingAddress()->collectTotals();
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->getShippingAddress()->collectShippingRates();
    $rates = $quote->getShippingAddress()->getShippingRatesCollection();
    
    foreach ($rates as $rate)
    {
    echo $rate->getPrice();
    }
    }
    

    最后一个 foreach 将为您提供启用的不同运输方式的运费。将它存储在任何变量中,并在 view.phtml 文件中的任何位置显示它。你完成了!

    【讨论】:

    • 在 Magento CE 1.9.3.6 上工作正常。
    • 只是一个小故障,因为不是每个人都住在丹麦:$quote->getShippingAddress()->setCountryId(Mage::getStoreConfig('general/country/default'));
    • 我已经在 Magento1 中成功使用这个选项好几年了,但我已经改用 Magento2。如何在 Magento2 的产品页面中显示每个产品的运费
    • 在 magento 1.9.4.4 对我不起作用。我可以调试到 $quote->getShippingAddress()->collectTotals();在它不起作用之后。有人可以帮助我吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    相关资源
    最近更新 更多