Created
May 11, 2015 09:30
-
-
Save codekipple/89862ec227e39541842b to your computer and use it in GitHub Desktop.
show estimated shipping rate magento - http://stackoverflow.com/questions/5640917/in-magento-how-can-i-put-an-items-shipping-cost-on-the-product-page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment