如何解决在Magento中,如何在商品页面上显示商品的运费?
| 我想在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
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();
}
}
?>
我已经编辑了原始帖子-但为了确认上面的代码有效。
,改进了一点:
<!-- SHOW SHIPPING RATES-->
<?php $quote = Mage::getModel(\'sales/quote\');
$quote->getShippingAddress()->setCountryId(\'ES\'); // Set your default shipping country here
$_product->getStockItem()->setUseConfigManageStock(false);
$_product->getStockItem()->setManageStock(false);
$quote->addProduct($_product);
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectTotals();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
// Find cheapest rate
$cheapestrate = null;
foreach ($rates as $rate) {
if (is_null($cheapestrate) || $rate->getPrice() < $cheapestrate) {
$cheapestrate = $rate->getPrice();
}
}
$corehelper = Mage::helper(\'core\');
if ($cheapestrate) {
echo \'<p><strong>Shipping costs:</strong> \' . $corehelper->currency($cheapestrate);?></p>
<?php
}else {
echo \"<strong>Free shipping</strong> for this product.\" ;
}?>
<!-- END SHOW SHIPPING RATES-->
顺便说一句:这仅适用于简单的产品。还没有时间调用相应的简单产品。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。