2

I want to show shipping price in product view page. In my view.phtml The shipping get a quote for shipping price is not working .I have called it by

<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?> 

I have also called the block in catalog.xml by

<block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="checkout/cart/shipping.phtml"/>

Any ideas why it is not working ?

1 Answer 1

1
<!-- 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-->

This only works for Simple products

3
  • Shipping cost estimation working on cart page but not working on the checkout page, what is the error?
    – Gem
    Commented Mar 6, 2018 at 7:28
  • @Rathinam you need to elaborate more about the issue maybe create a question about it Commented Mar 6, 2018 at 12:08
  • Someone posted the same issue, help @ magento.stackexchange.com/q/216132/57334
    – Gem
    Commented Mar 7, 2018 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.