Have you ever stuck with automatically select shipping method in magento ?
For example in this tutorial, we assumed that we had only one shipping method : free-shipping. So, we need to set it as default shipping method and ignore shipping step.
We can make it done with these simple steps:
1/Create app/etc/modules/Inbusiness_Checkout.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <Inbusiness_Checkout> <active>true</active> <codePool>local</codePool> </Inbusiness_Checkout> </modules> </config> |
2/Create app/code/local/Inbusiness/Checkout/etc/config.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0"?> <config> <modules> <Inbusiness_Checkout> <version>1.1.1</version> </Inbusiness_Checkout> </modules> <frontend> <routers> <checkout> <use>standard</use> <args> <modules> <Inbusiness_Checkout before="Mage_Checkout">Inbusiness_Checkout</Inbusiness_Checkout> </modules> </args> </checkout> </routers> </frontend> </config> |
3/ Create app/code/local/Inbusiness/Checkout/controllers/OnepageController.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
<?php require_once 'Mage/Checkout/controllers/OnepageController.php'; class Inbusiness_Checkout_OnepageController extends Mage_Checkout_OnepageController { public function saveBillingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { // $postData = $this->getRequest()->getPost('billing', array()); // $data = $this->_filterPostData($postData); $data = $this->getRequest()->getPost('billing', array()); $customerAddressId = $this->getRequest()->getPost('billing_address_id', false); if (isset($data['email'])) { $data['email'] = trim($data['email']); } $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'] = 'shipping_method'; $result['update_section'] = array( 'name' => 'shipping-method', 'html' => $this->_getShippingMethodsHtml() ); $result['allow_sections'] = array('shipping'); $result['duplicateBillingInfo'] = 'true'; $method = 'freeshipping_freeshipping'; $result = $this->getOnepage()->saveShippingMethod($method); if(!$result) { Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote())); $this->getOnepage()->getQuote()->collectTotals(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } $this->getOnepage()->getQuote()->collectTotals()->save(); } else { $result['goto_section'] = 'shipping'; } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } /** * Override Shipping address save action */ 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'])) { $method = 'freeshipping_freeshipping'; $result = $this->getOnepage()->saveShippingMethod($method); if(!$result) { Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote())); $this->getOnepage()->getQuote()->collectTotals(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } $this->getOnepage()->getQuote()->collectTotals()->save(); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } } |
Happy coding !
POST HASN'T TAG.