【发布时间】:2011-08-04 04:44:45
【问题描述】:
我想在 Magento 的实际产品页面上显示运费,以便客户可以看到他们的运费。我可以从购物篮页面添加运费估算器。但我真正想要的只是产品价格下的一行文字,说明运费为 £XX.XX
我看过本教程:http://aneeshsreedharan.wordpress.com/2010/04/28/estimating-shipping-rate-on-product-details-page-in-magento/#comment-10,但它不适用于 Magento 1.4.2 - 我认为本教程使用的是旧版本。
我目前使用的是基于重量的表运费方式,只有一个选项。
编辑:我最终解决了问题:令人尴尬的是,我没有意识到博客正在剥离格式。它正在将 ' 更改为 '
我现在可以确认下面的代码确实显示了运费:
<?php
if($_product->isSaleable())
{
$quote = Mage::getModel('sales/quote');
$quote->getShippingAddress()->setCountryId('*');
$quote->addProduct($_product);
$quote->getShippingAddress()->collectTotals();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
foreach ($rates as $rate)
{
echo $rate->getPrice();
}
}
?>
【问题讨论】:
标签: php zend-framework magento shipping