Customizing Onepage Checkout - Remove shipping_method

Last modified by FerdiUSA on Fri, June 25, 2010 09:27
Source|Old Revisions  

This is an old revision of the document!


Summary

This HowTo will show you which files you need to modify to remove the shipping_method block from OnepageCheckout. The customer will not be able to specify a shipping method and the order will be placed with “free shipping” by default.

Tested on Magento ver. 1.3.1

You will need to modify the following two core files and one template file, originally found in these locations:

  1. Block app/code/core/Mage/Checkout/Block/Onepage.php
  2. Controller app/code/core/Mage/Checkout/controllers/OnepageController.php
  3. Template design/frontend/default/default/template/checkout/onepage/progress.phtml

1. Block (Onepage.php)

Overwrite the function getSteps() and replace the line:

  1. $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');

with the following:

  1. $stepCodes = array('billing', 'shipping', 'payment', 'review');

2. Controller (OnepageController.php)

Overwrite the function saveBillingAction() with the following code:

  1. public function saveBillingAction()
  2. {
  3.     $this->_expireAjax();
  4.     if ($this->getRequest()->isPost()) {
  5.         $data = $this->getRequest()->getPost('billing', array());
  6.         $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
  7.         $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
  8.  
  9.         if (!isset($result['error'])) {
  10.             /* check quote for virtual */
  11.             if ($this->getOnepage()->getQuote()->isVirtual()) {
  12.                 $result['goto_section'] = 'payment';
  13.                 $result['update_section'] = array(
  14.                     'name' => 'payment-method',
  15.                     'html' => $this->_getPaymentMethodsHtml()
  16.                 );
  17.             }
  18.             elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
  19.  
  20.             $result['goto_section'] = 'payment';
  21.             $result['update_section'] = array(
  22.                 'name' => 'payment-method',
  23.                 'html' => $this->_getPaymentMethodsHtml()
  24.             );
  25.             }
  26.             else {
  27.                 $result['goto_section'] = 'shipping';
  28.             }
  29.         }
  30.         $this->getResponse()->setBody(Zend_Json::encode($result));
  31.     }
  32. }

Overwrite the function saveShippingAction() with the following:

  1. public function saveShippingAction()
  2. {
  3.     $this->_expireAjax();
  4.     if ($this->getRequest()->isPost()) {
  5.         $this->saveShippingMethodAction();
  6.         $data = $this->getRequest()->getPost('shipping', array());
  7.         $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
  8.         $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
  9.  
  10.         if (!isset($result['error'])) {
  11.             $result['goto_section'] = 'payment';
  12.             $result['update_section'] = array(
  13.                 'name' => 'payment-method',
  14.                 'html' => $this->_getPaymentMethodsHtml()
  15.             );
  16.         }
  17.  
  18. //        $this->loadLayout('checkout_onepage_shippingMethod');
  19. //        $result['shipping_methods_html'] = $this->getLayout()->getBlock('root')->toHtml();
  20. //        $result['shipping_methods_html'] = $this->_getShippingMethodsHtml();
  21.         $this->getResponse()->setBody(Zend_Json::encode($result));
  22.     }
  23. }

Overwrite the function saveShippingMethodAction() with the following code: Please Note: the shipping method “Free Shipping” must be enabled for this to work.

  1. public function saveShippingMethodAction()
  2. {
  3.     $this->_expireAjax();
  4.     if ($this->getRequest()->isPost()) {
  5.         $data = $this->getRequest()->getPost('shipping_method', 'freeshipping_freeshipping');
  6.         $result = $this->getOnepage()->saveShippingMethod($data);
  7.            
  8.         /*
  9.         $result will have erro data if shipping method is empty
  10.         */
  11.         if(!$result) {
  12.             Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote()));
  13.             $this->getResponse()->setBody(Zend_Json::encode($result));
  14.                
  15.             $result['goto_section'] = 'payment';
  16.             $result['update_section'] = array(
  17.                 'name' => 'payment-method',
  18.                 'html' => $this->_getPaymentMethodsHtml()
  19.             );
  20.  
  21.             //$result['payment_methods_html'] = $this->_getPaymentMethodsHtml();
  22.         }
  23.         $this->getResponse()->setBody(Zend_Json::encode($result));
  24.     }
  25. }

Overwrite function saveOrderAction() and insert a function call for saveShippingMethodAction() as shown below:

  1. public function saveOrderAction()
  2. {
  3.     $this->_expireAjax();
  4.     $this->saveShippingMethodAction();
  5.  
  6.     ...
  7. }

3. Template (progress.phtml)

to not show the step to the customer, you need to comment out lines 60 to 89 (default template):

<?php if ($this->getCheckout()->getStepData('shipping_method', 'is_show')): ?>
    <?php if ($this->getCheckout()->getStepData('shipping_method', 'complete')): ?>
        <li>
            <h4 class="complete"><?php echo $this->__('Shipping Method') ?> <span class="separator">|</span> <a href="#shipping_method" onclick="checkout.accordion.openSection('opc-shipping_method'); return false;"><?php echo $this->__('Change') ?></a></h4>
            <div class="content">
            <?php if ($this->getShippingMethod()): ?>
                <?php echo $this->getShippingDescription(); ?>

                <?php $_excl = $this->getShippingPriceExclTax(); ?>
                <?php $_incl = $this->getShippingPriceInclTax(); ?>
                <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
                    <?php echo $_incl; ?>
                <?php else: ?>
                    <?php echo $_excl; ?>
                <?php endif; ?>
                <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                    (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                <?php endif; ?>

            <?php else: ?>
                <?php echo $this->__('Shipping method has not been selected yet') ?>
            <?php endif ?>
            </div>
        </li>
    <?php else: ?>
        <li>
            <h4><?php echo $this->__('Shipping Method') ?></h4>
        </li>
    <?php endif; ?>
    <?php endif; ?>



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs