Monday, 21 April 2014

Remove shipping method and Order review step module Magento


Remove shipping method and Order review step module Magento

Here i have make one module for remove Shipping method and Order review steps...
My module name is chand_skiping

Put Chand_Skiping.xml at app/etc/modules and write below code in this file..

<?xml version="1.0"?>
<config>
    <modules>
        <Chand_Skiping>
            <active>true</active>
            <codePool>local</codePool>
        </Chand_Skiping>
    </modules>
</config>

To override Onepagecontroller put the OnepageController.php at app\code\local\Chand\Skiping\controllers
Write below code :

require_once 'Mage/Checkout/controllers/OnepageController.php';
class Chand_Skiping_OnepageController extends Mage_Checkout_OnepageController
{

    /**
     * save checkout billing address
     */
    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);

            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) {
                    $method = $this->getAutoShippingMethod($data, $customerAddressId);
                    if (!empty($method)) {
                        $result = $this->getOnepage()->saveShippingMethod($method);
$this->getOnepage()->getQuote()->collectTotals();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
$this->getOnepage()->getQuote()->collectTotals()->save();

                        if(!$result) {
                            Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
                                'request'=>$this->getRequest(),
                                'quote'=>$this->getOnepage()->getQuote()
                            ));
                            $result['goto_section'] = 'payment';
                            $result['update_section'] = array(
                                'name' => 'payment-method',
                                'html' => $this->_getPaymentMethodsHtml()
                            );
                        }
                    } else {
                        $result['goto_section'] = 'shipping_method';
                        $result['update_section'] = array(
                            'name' => 'shipping-method',
                            'html' => $this->_getShippingMethodsHtml()
                        );

                        $result['allow_sections'] = array('shipping');
                        $result['duplicateBillingInfo'] = 'true';
                    }
                } else {
                    $result['goto_section'] = 'shipping';
                }
            }

            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

/**
     * 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 = $this->getAutoShippingMethod($data, $customerAddressId);
                if (!empty($method)) {
                    if(!$result) {
                        Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
                            'request'=>$this->getRequest(),
                            'quote'=>$this->getOnepage()->getQuote()
                        ));
                        $result['goto_section'] = 'payment';
                        $result['update_section'] = array(
                            'name' => 'payment-method',
                            'html' => $this->_getPaymentMethodsHtml()
                        );
                    }                  
                } else {
                    $result['goto_section'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );
                }
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

 
   public function getAutoShippingMethod($data, $customerAddressId)
    {
        return 'flatrate_flatrate';
    }

/**
     * Save payment ajax action
     *
     * Sets either redirect or a JSON response
     */
    public function savePaymentAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        try {
            if (!$this->getRequest()->isPost()) {
                $this->_ajaxRedirectResponse();
                return;
            }

            // set payment to quote
            $result = array();
            $data = $this->getRequest()->getPost('payment', array());
            $result = $this->getOnepage()->savePayment($data);

            // get section and redirect data
            $redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
            if (empty($result['error']) && !$redirectUrl) {
                $this->loadLayout('checkout_onepage_review');
                $result['goto_section'] = 'review';
                $result['update_section'] = array(
                    'name' => 'review',
                    'html' => $this->_getReviewHtml()
                );
            }
            if ($redirectUrl) {
                $result['redirect'] = $redirectUrl;
            }
        } catch (Mage_Payment_Exception $e) {
            if ($e->getFields()) {
                $result['fields'] = $e->getFields();
            }
            $result['error'] = $e->getMessage();
        } catch (Mage_Core_Exception $e) {
            $result['error'] = $e->getMessage();
        } catch (Exception $e) {
            Mage::logException($e);
            $result['error'] = $this->__('Unable to set Payment Method.');
        }

$result['redirect'] = '';
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
$this->saveOrderAction();
    }

/**
     * Create order action
     */
    public function saveOrderAction()
    {
        if ($this->_expireAjax()) {
            return;
        }

        $result = array();
        try {
            if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
                $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
                if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
                    $result['success'] = false;
                    $result['error'] = true;
                    $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
                    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
                    return;
                }
            }
            if ($data = $this->getRequest()->getPost('payment', false)) {
                $this->getOnepage()->getQuote()->getPayment()->importData($data);
            }
            $this->getOnepage()->saveOrder();

            $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
            $result['success'] = true;
            $result['error']   = false;
        } catch (Mage_Payment_Model_Info_Exception $e) {
            $message = $e->getMessage();
            if( !empty($message) ) {
                $result['error_messages'] = $message;
            }
            $result['goto_section'] = 'payment';
            $result['update_section'] = array(
                'name' => 'payment-method',
                'html' => $this->_getPaymentMethodsHtml()
            );
        } catch (Mage_Core_Exception $e) {
            Mage::logException($e);
            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
            $result['success'] = false;
            $result['error'] = true;
            $result['error_messages'] = $e->getMessage();

            if ($gotoSection = $this->getOnepage()->getCheckout()->getGotoSection()) {
                $result['goto_section'] = $gotoSection;
                $this->getOnepage()->getCheckout()->setGotoSection(null);
            }

            if ($updateSection = $this->getOnepage()->getCheckout()->getUpdateSection()) {
                if (isset($this->_sectionUpdateFunctions[$updateSection])) {
                    $updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection];
                    $result['update_section'] = array(
                        'name' => $updateSection,
                        'html' => $this->$updateSectionFunction()
                    );
                }
                $this->getOnepage()->getCheckout()->setUpdateSection(null);
            }
        } catch (Exception $e) {
            Mage::logException($e);
            Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
            $result['success']  = false;
            $result['error']    = true;
            $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');
        }
        $this->getOnepage()->getQuote()->save();
        /**
         * when there is redirect to third party, we don't want to save order yet.
         * we will save the order in return action.
         */
        if (isset($redirectUrl)) {
            $result['redirect'] = $redirectUrl;
        }
else
{
$result['redirect'] = Mage::getUrl('*/*/success');
}

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }


}

Now put config.xml at app/code/local/Chand/Skiping/etc/ and put below code

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
 <Chand_Skiping>
 <version>0.0.2</version>
 </Chand_Skiping>
  </modules>
  <global>
 <blocks>
 <checkout>
 <rewrite>
<onepage_shipping_method>Chand_Skiping_Block_Onepage_Shipping_Method</onepage_shipping_method>
 </rewrite>
 </checkout>
   <checkout>
 <rewrite>
<onepage_review>Chand_Skiping_Block_Onepage_Review</onepage_review>
 </rewrite>
 </checkout>
 </blocks>
  </global>
  <frontend>
 <routers>
 <checkout>
 <args>
 <modules>
 <Chand_skiping before="Mage_Checkout">Chand_Skiping</Chand_skiping>
 </modules>
 </args>
 </checkout>
 </routers>
  </frontend>
</config>

To hide shipping method put Method.php at app/code/local/Chand/Skiping/Block/Onepage/Shipping/

class Chand_Skiping_Block_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Abstract
{
    protected function _construct()
    {
        $this->getCheckout()->setStepData('shipping_method', array(
            'label'     => Mage::helper('checkout')->__('Shipping Method'),
            'is_show'   => $this->isShow()
        ));
        parent::_construct();
    }

    /**
     * Retrieve is allow and show block
     *
     * @return bool
     */
    public function isShow()
    {
        //return !$this->getQuote()->isVirtual();
return false;
    }
}

To hide review step put Review.php at app/code/local/Chand/Skiping/Block/Onepage/

class Chand_Skiping_Block_Onepage_Review extends Mage_Checkout_Block_Onepage_Abstract
{
    protected function _construct()
    {
        $this->getCheckout()->setStepData('review', array(
            'label'     => Mage::helper('checkout')->__('Order Review'),
            'is_show'   => $this->isShow()
        ));
        parent::_construct();

        $this->getQuote()->collectTotals()->save();
    }
public function isShow()
    {
        return false;
    }
}

Now check on front end at checkout... Enjoy Chandresh rana's coding... :)

11 comments:

Unknown said...

Hello Rana ,

How i can disable it from other store. i want to enable only one store

PHP Coder said...

Sorry Mate,

Above code is for global store. If you want to disable this code for particular store you have to put store condition in every touching files..

Anonymous said...

I want to remove shipping_method only. what changes I have to do in this module??

Unknown said...

its not moving to next tab, If you give continue in billing information it remains in the same tab.
Kindly help me with this one

PHP Coder said...

Hello vasanth,

Please follow above steps carefully , it works completely at my end...

Anonymous said...

Thanks a lot

It is working fine

Anonymous said...

Floowed all steps as given in your blog to remove shipping method but getting this error

a:5:{i:0;s:51:"Controller file was loaded but class does not exist";i:1;s:1012:"#0 /home/myhatti/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(326): Mage::exception('Mage_Core', 'Controller file...')
#1 /home/myhatti/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(293): Mage_Core_Controller_Varien_Router_Standard->_includeControllerClass('/home/myhatti/p...', 'Chand_Skiping_O...')
#2 /home/myhatti/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(196): Mage_Core_Controller_Varien_Router_Standard->_validateControllerClassName('Chand_Skiping', 'onepage')
#3 /home/myhatti/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 /home/myhatti/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 /home/myhatti/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#6 /home/myhatti/public_html/home.php(87): Mage::run('', 'store')
#7 {main}";s:3:"url";s:27:"/home.php/checkout/onepage/";s:11:"script_name";s:9:"/home.php";s:4:"skin";s:7:"default";}

Anonymous said...

hi,

I used this code. i want to just remove order review step from checkout page.

its work correctly when i am using check and money order OR bank transfer.
But its not woring for paypal express checkout

Its not going on Paypal url

so please give me solution.

Thanks

Romee Prajapati said...

I want to change shopping cart to enquiry cart. I don't need billing shipping payment at all but I need order review. Do you know how to do this?

I can use module to remove shipping and payment. I manage to remove billing too but my order review doesn't open itself when I go to checkout page.

Unknown said...

Hello,

I have followed all the steps completely. However, it stuck at the Payment Method and not placing the Order.

What am I missing? Please help.

Thanks

Anonymous said...

Hello,
I just want to remove Review Order Step from Checkout. So what all changes I need to do in this code?
Or do you have any other Blog for this.

Please help.


Thanks in advance