在 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();
}
}
?>
I want to put a shipping cost on the actual product page in Magento, so customers can see how much it will cost them. I can add in the shipping estimator from the basket page. But all i actually want is a line of text under the product price saying shipping from £XX.XX
I have seen this tutorial: http://aneeshsreedharan.wordpress.com/2010/04/28/estimating-shipping-rate-on-product-details-page-in-magento/#comment-10 but it is not working for me on Magento 1.4.2 - i think this an older version is used on this tutorial.
I am using a weight based table rate shipping method at the moment, with only one option.
EDIT: I worked out the problem in the end: Rather embarrasingly I didnt realise the blog was stripping the formatting out. It was changing the ' to a ‘
I can now confirm the code below does display the shipping:
<?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();
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终解决了这个问题:相当尴尬的是,我没有意识到博客正在剥离格式。它将 ' 更改为 '
我现在可以确认下面的代码确实显示发货:
我已经编辑了我的原始帖子 - 但要确认上面的代码是否有效。
I worked out the problem in the end: Rather embarrasingly I didnt realise the blog was stripping the formatting out. It was changing the ' to a ‘
I can now confirm the code below does display shipping:
I have edited my original post - but to confirm the code above works.
稍微改进一下:
顺便说一句:这只适用于简单的产品。还没有时间去调用相应的简单产品。
Improved it a bit:
Btw: This only works with simple products. Haven't had the time yet to call the corresponding simple product.