![](/img/trans.png)
[英]in Magento, how can i put shipping cost on the product page for a configurable product?
[英]In Magento, how can i put an items shipping cost on the product page?
我想在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-->
順便說一句:這只適用於簡單的產品。 還沒有時間打電話給相應的簡單產品。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.