Showing posts with label Remove order review step in magento. Show all posts
Showing posts with label Remove order review step in magento. Show all posts

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... :)