Customizing Onepage Checkout - Remove shipping_method
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:
- Block Digg/Checkout/Block/Onepage/Shipping/Method.php
- Controller Digg/Checkout/controllers/OnepageController.php
- Model Digg/Checkout/Model/Type/Onepage.php
- 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:
- class Digg_Checkout_Block_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Shipping_Method
- {
- public function isShow()
- {
- return false;
- }
- }
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:
- require_once 'Mage/Checkout/controllers/OnepageController.php';
- class Digg_Checkout_OnepageController extends Mage_Checkout_OnepageController
- {
- public function saveShippingAction()
- {
- if ($this->_expireAjax()) {
- return;
- }
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost('shipping', array());
- $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
- $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
- if (!isset($result['error'])) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
- }
- }
- public function saveBillingAction()
- {
- if ($this->_expireAjax()) {
- return;
- }
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost('billing', array());
- $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
- $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
- if (!isset($result['error'])) {
- /* check quote for virtual */
- if ($this->getOnepage()->getQuote()->isVirtual()) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- else {
- $result['goto_section'] = 'shipping';
- }
- }
- $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
- }
- }
- }
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
- class Digg_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
- {
- protected function validateOrder()
- {
- $helper = Mage::helper('checkout');
- if ($this->getQuote()->getIsMultiShipping()) {
- Mage::throwException($helper->__('Invalid checkout type.'));
- }
- $addressValidation = $this->getQuote()->getBillingAddress()->validate();
- if ($addressValidation !== true) {
- Mage::throwException($helper->__('Please check billing address information.'));
- }
- if (!($this->getQuote()->getPayment()->getMethod())) {
- Mage::throwException($helper->__('Please select valid payment method.'));
- }
- }
- }
4. Configuration (config.xml) |
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.
- <?xml version="1.0" encoding="UTF-8"?>
- <config>
- <modules>
- <Digg_Checkout>
- <version>0.0.2</version>
- </Digg_Checkout>
- </modules>
- <global>
- <models>
- <checkout>
- <rewrite>
- <type_onepage>Digg_Checkout_Model_Type_Onepage</type_onepage>
- </rewrite>
- </checkout>
- </models>
- <blocks>
- <checkout>
- <rewrite>
- <onepage_shipping_method>Digg_Checkout_Block_Onepage_Shipping_Method</onepage_shipping_method>
- </rewrite>
- </checkout>
- </blocks>
- </global>
- <frontend>
- <routers>
- <checkout>
- <args>
- <modules>
- <checkoutdigg before="Mage_Checkout">Digg_Checkout</checkoutdigg>
- </modules>
- </args>
- </checkout>
- </routers>
- </frontend>
- </config>
Don’t forget to register your module in app/etc/modules/Digg_All.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <config>
- <modules>
- <Digg_Checkout>
- <active>true</active>
- <codePool>local</codePool>
- </Digg_Checkout>
- </modules>
- </config>


