Magento 1.9 如何在Magento 1.9.1的产品页面中显示每个产品的运输成本

Magento 1.9 如何在Magento 1.9.1的产品页面中显示每个产品的运输成本,magento-1.9,shipping,Magento 1.9,Shipping,是否有办法在Magento 1.9.1的产品详细信息页面中显示产品成本? 我希望每个产品都能显示相关的运输成本,非常感谢您可以将以下代码粘贴到主题中的“/template/catalog/product/view.phtml”文件中 if($_product->isSaleable()) { $quote = Mage::getModel('sales/quote'); $quote->getShippingAddress()->setCountryId('DK'); $quo

是否有办法在Magento 1.9.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。如何实现在magento 2的产品页面中显示每个产品的运输成本在magento 1.9.4.4中对我不起作用。我可以调试到$quote->getShippingAddress()->collectTotals();之后它就不起作用了。有人能帮我吗?