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
<?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
<?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
<?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.
COMMENTS