Customizing Onepage Checkout - Remove shipping_method

Last modified by Jeje on Wed, October 27, 2010 06:14
Source|Old Revisions  

This is an old revision of the document!


Summary

Old variant which was here proposed, changing Magento core classes, that is fully wrong decision. You must follow the application model. This method tested on 1.4+ versions.

Give our namespace name - “Digg“. So you have a folder in app/local/Digg for modules and module “Checkout”.

You must add next files to you module:

  1. Block Digg/Checkout/Block/Onepage/Shipping/Method.php
  2. Controller Digg/Checkout/controllers/OnepageController.php
  3. Model Digg/Checkout/Model/Type/Onepage.php
  4. Configuration Digg/Checkout/etc/config.xml

1. Block (Method.php)

To disable Shipping Method for checkout list, you must hide it. Our custom shipping method inherited from core Mage_Checkout_Block_Onepage_Shipping_Method class. Overload method isShow and return false:

  1. class Digg_Checkout_Block_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Shipping_Method
  2. {
  3.     public function isShow()
  4.     {
  5.         return false;//!$this->getQuote()->isVirtual();
  6.     }
  7. }

2. Controller (OnepageController.php)

Important:Controllers have no autoloading so you must include it manualy. Overwrite the function saveShippingAction() to skip shipping method to payment with the following code:

  1. require_once 'Mage/Checkout/controllers/OnepageController.php';
  2.  
  3. class Digg_Checkout_OnepageController extends Mage_Checkout_OnepageController
  4. {
  5.        public function saveShippingAction()
  6.     {
  7.         if ($this->_expireAjax()) {
  8.             return;
  9.         }
  10.         if ($this->getRequest()->isPost()) {
  11.             $data = $this->getRequest()->getPost('shipping', array());
  12.             $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
  13.             $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
  14.  
  15.             if (!isset($result['error'])) {
  16.                 $result['goto_section'] = 'payment';
  17.                 $result['update_section'] = array(
  18.                     'name' => 'payment-method',
  19.                     'html' => $this->_getPaymentMethodsHtml()
  20.                 );
  21.             }
  22.             $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
  23.         }
  24.     }
  25. }

3. Model (Onepage.php)

The simplest way to ask magento to ignore shipping info is to change validation rule. Te following code overwriting validateOrder() method. I just removed part of original code that validate non-virtual products

  1. class Digg_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
  2. {
  3.     protected function validateOrder()
  4.     {
  5.         $helper = Mage::helper('checkout');
  6.         if ($this->getQuote()->getIsMultiShipping()) {
  7.             Mage::throwException($helper->__('Invalid checkout type.'));
  8.         }
  9.  
  10.         $addressValidation = $this->getQuote()->getBillingAddress()->validate();
  11.         if ($addressValidation !== true) {
  12.             Mage::throwException($helper->__('Please check billing address information.'));
  13.         }
  14.  
  15.         if (!($this->getQuote()->getPayment()->getMethod())) {
  16.             Mage::throwException($helper->__('Please select valid payment method.'));
  17.         }
  18.     }
  19. }

4. Configuration (Onepage.php)

Last step is configurate our module. The main idea is to ask Magento first searching action methods in our Digg module and if it didn’t found use core.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <config>
  4.     <modules>
  5.         <Digg_Checkout>
  6.             <version>0.0.2</version>
  7.         </Digg_Checkout>
  8.     </modules>
  9.     <global>
  10.         <models>
  11.             <checkout>
  12.                 <rewrite>
  13.                     <type_onepage>Digg_Checkout_Model_Type_Onepage</type_onepage>
  14.                 </rewrite>
  15.             </checkout>
  16.         </models>
  17.  
  18.         <blocks>
  19.             <checkout>
  20.                 <rewrite>
  21.                     <type_onepage>Digg_Checkout_Model_Type_Onepage</type_onepage>
  22.                 </rewrite>
  23.             </checkout>
  24.         </blocks>     
  25.     </global>
  26.  
  27.     <frontend>
  28.         <routers>
  29.             <checkout>
  30.                 <args>
  31.                     <modules>
  32.                         <checkoutdigg before="Mage_Checkout">Digg_Checkout</checkoutdigg>
  33.                     </modules>
  34.                 </args>
  35.             </checkout>
  36.         </routers>
  37.     </frontend>
  38.    
  39. </config>

Don’t forget to register your module in app/etc/modules/Digg_All.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <config>
  3.     <modules>
  4.         <Digg_Checkout>
  5.             <active>true</active>
  6.             <codePool>local</codePool>
  7.         </Digg_Checkout>
  8.     </modules>
  9. </config>



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs