【发布时间】:2016-09-16 02:45:29
【问题描述】:
有没有办法在 Magento 1.9.1 的产品详细信息页面中显示产品成本? 我希望每个产品都显示相关的运费,非常感谢
【问题讨论】:
标签: magento-1.9 shipping
有没有办法在 Magento 1.9.1 的产品详细信息页面中显示产品成本? 我希望每个产品都显示相关的运费,非常感谢
【问题讨论】:
标签: magento-1.9 shipping
您可以将以下代码粘贴到主题中的“/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 文件中的任何位置显示它。你完成了!
【讨论】:
$quote->getShippingAddress()->setCountryId(Mage::getStoreConfig('general/country/default'));