0

I am trying to add shipping estimates onto a CMS page in Magento to display shipping methods, estimated shipping delivery dates and rates etc...

I have a module (meanbee estimated delivery) which gives me access to this information in the the Shipping step of the checkout page but I would also like to display the values on a CMS page.

Here is what I have so far:

I have created a CMS page called shipping-delivery and added this to the content

{{block type="checkout/onepage/shipping_method/available" template="meanbee/estimated_delivery/cms/cms-available.phtml"}}

then inside of my cms-available.phtml file I have

<?php $_shippingRateGroups = $this->getShippingRates(); ?>
<?php if (!$_shippingRateGroups): ?>
    <p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else: ?>
    <dl class="sp-methods">
        <?php $shippingCodePrice = array(); ?>
        <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
            <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
            <dd>
                <ul>
                    <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
                        <?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
                        <li>
                            <?php if ($_rate->getErrorMessage()): ?>
                                <ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
                            <?php else: ?>
                                <?php if ($_sole) : ?>
                                    <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
                                <?php else: ?>
                                <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>

                                <?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
                                    <script type="text/javascript">
                                        //<![CDATA[
                                        lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
                                        //]]>
                                    </script>
                                <?php endif; ?>

                                <?php endif; ?>
                                <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
                                    <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                                    <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
                                    <?php echo $_excl; ?>
                                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                        (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                                    <?php endif; ?>
                                </label>
                                <!-- START MEANBEE ESTIMATED DELIVERY -->
                                <br/><?php echo Mage::helper('meanbee_estimateddelivery')->getEstimatedDeliveryText($_rate->getCode()); ?>
                                <!-- END MEANBEE ESTIMATED DELIVERY -->
                            <?php endif ?>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </dd>
        <?php endforeach; ?>
    </dl>
    <script type="text/javascript">
        //<![CDATA[
        <?php if (!empty($shippingCodePrice)): ?>
        var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
        <?php endif; ?>

        $$('input[type="radio"][name="shipping_method"]').each(function(el){
            Event.observe(el, 'click', function(){
                if (el.checked == true) {
                    var getShippingCode = el.getValue();
                    <?php if (!empty($shippingCodePrice)): ?>
                    var newPrice = shippingCodePrice[getShippingCode];
                    if (!lastPrice) {
                        lastPrice = newPrice;
                        quoteBaseGrandTotal += newPrice;
                    }
                    if (newPrice != lastPrice) {
                        quoteBaseGrandTotal += (newPrice-lastPrice);
                        lastPrice = newPrice;
                    }
                    <?php endif; ?>
                    checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
                    return false;
                }
            });
        });
        //]]>
    </script>
<?php endif; ?>

The problem is I get this message when I browse to my cms page:

Sorry, no quotes are available for this order at this time. 

I'm not sure what I am missing out so could do with a nudge if anyone can help me out?

  • As a suggestion - have you thought about doing it on a business level and keeping it simple with a flat rate building it in to the margins - this is how the large enterprise companies do it as it reduces workload and simplfies customer experience. That way there is no technology involved. – user2935 Jul 29 '14 at 9:33
1

I suppose that problem is here:

<?php $_shippingRateGroups = $this->getShippingRates(); ?>

For me you don't have method getShippingRates in core/template block, maybe you must call proper block from your module, not from magento core.

  • Thank for your comment, I'm now using checkout/onepage/shipping_method/available But I still get the message :( Not sure which block to use here... – user1704524 Jul 28 '14 at 20:14
  • There should be block from meanbee estimated delivery extension. Search for method getShippingRates() in extension blocks. – kuba_ceg Jul 29 '14 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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