Magento Onestep Checkout – Remove Login Step

In this blog post, we are going to see how to remove the first step from checkout page.

The basics idea of removing any step from checkout is
1. Change javascript and HTML to remove the step display
2. Set default values in Quote object for the step removed, so that checkout process goes smoothly.
If we need to remove the login step there are 3 different ways.
1. Checkout will be done only as guest
2. Checkout will be done only for registered users
3. Checkout will only be available for logged in users.
Now lets go into detail on how to remove the login step. First i have created a module for this called Excellence_Remove for this blog. Attached is source code of module to remove step1.
[dm]8[/dm]

Step1: Onepage Block

First we need to override the Onepage.php block, so that we can change the steps array. So to override the block Mage_Checkout_Block_Onepage open your module’s config.xml file and put inside the blocks tag, below code

 <checkout>
	    		<rewrite>
	    			<onepage>Excellence_Remove_Block_Onepage</onepage>
	    		</rewrite>
	    	</checkout>

So the core block Mage_Checkout_Block_Onepage has been overridden by Excellence_Remove_Block_Onepage block. In the code in this block is

<?php
class Excellence_Remove_Block_Onepage extends Mage_Checkout_Block_Onepage
{
	public function getSteps()
	{
		$steps = array();

		if (!$this->isCustomerLoggedIn()) {
			//$steps['login'] = $this->getCheckout()->getStepData('login');
		}

		$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');

		foreach ($stepCodes as $step) {
			$steps[$step] = $this->getCheckout()->getStepData($step);
		}
		return $steps;
	}

	public function getActiveStep()
	{
		//return $this->isCustomerLoggedIn() ? 'billing' : 'login';
		return $this->isCustomerLoggedIn() ? 'billing' : 'billing';
	}
}

So here as we can see i have removed the ‘login’ step from the $stepCodes array and also made the ‘billing’ step the default active step.

Step2: PHTML and Javascript

Here basically, we need to change the login step javascript, so we need to add our javascript file. So we add our javascript file in onepage.phtml

<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/removecheckout.js') ?>"></script>

and now the code of our javascript file would be

var Excellence = Class.create(Checkout, {
	initialize: function($super,accordion, urls){
		$super(accordion, urls);
		//New Code Addded
		this.steps = ['billing', 'shipping', 'shipping_method', 'payment', 'review'];
	},
	setMethodGuest: function(){
		Element.hide('register-customer-password');
	},
	setMethodRegister: function(){
		Element.show('register-customer-password');
	}
});

Here we have created to function setMethodGuest and setMethodRegister. These functions will be called in onepage.phtml file depending on the type of our checkout. So in the onepage.phtml file this is the changes we will make

<script type="text/javascript">
//<![CDATA[
    var accordion = new Accordion('checkoutSteps', '.step-title', true);
    <?php if($this->getActiveStep()): ?>
    accordion.openSection('opc-<?php echo $this->getActiveStep() ?>');
    <?php endif ?>
    //New Code Added Below
    var checkout = new Excellence(accordion,{
        progress: '<?php echo $this->getUrl('checkout/onepage/progress') ?>',
        review: '<?php echo $this->getUrl('checkout/onepage/review') ?>',
        saveMethod: '<?php echo $this->getUrl('checkout/onepage/saveMethod') ?>',
        failure: '<?php echo $this->getUrl('checkout/cart') ?>'}
    );
    //If Guest Method Checkout
    checkout.setMethodGuest();
    
    //If Register Method Checkout,uncomment code below
    //checkout.setMethodRegister();
//]]>
</script>

For the full code please check the moduel.

Step3: Checkout Onepage Controller

Next we need to change the onepage controller, so that we can set default checkout method in the indexAction. Here is the code to add

public function indexAction()
	{
		if (!Mage::helper('checkout')->canOnepageCheckout()) {
			Mage::getSingleton('checkout/session')->addError($this->__('The onepage checkout is disabled.'));
			$this->_redirect('checkout/cart');
			return;
		}
		$quote = $this->getOnepage()->getQuote();
		if (!$quote->hasItems() || $quote->getHasError()) {
			$this->_redirect('checkout/cart');
			return;
		}
		if (!$quote->validateMinimumAmount()) {
			$error = Mage::getStoreConfig('sales/minimum_order/error_message');
			Mage::getSingleton('checkout/session')->addError($error);
			$this->_redirect('checkout/cart');
			return;
		}

		Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
		Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure'=>true)));
		$this->getOnepage()->initCheckout();
		$this->loadLayout();
		$this->_initLayoutMessages('customer/session');
		$this->getLayout()->getBlock('head')->setTitle($this->__('Checkout'));

		//If you want guest checkout by default
		$method = Mage_Checkout_Model_Type_Onepage::METHOD_GUEST;
		$this->getOnepage()->saveCheckoutMethod($method);
		
		//If you want register checkout by default, uncomment code below
		/*
		 $method = Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
		 $this->getOnepage()->saveCheckoutMethod($method);
		*/
		

		//If you want only logged in users to be able to checkout, uncomment code below
		/*
		if(!Mage::getModel('customer/session')->isLoggedIn()){
			$this->_redirect('customer/account/login');
		}else{
			$method = Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER;
			$this->getOnepage()->saveCheckoutMethod($method);
		}
		*/

		$this->renderLayout();
	}

This is all that is required to remove the login step. In the module code, all the 3 types of checkout have been you need to comment and uncomment in the files OnepageController.php and onepage.phtml

  • Yaboosa

    Thank you for this tutorial, it was helpful for me. Now I’m trying to  have “billing”, “shipping” and “payment” on 1 step and a second step for review, but without success, and it is giving me a headache, could you please give some help with that. Thank you.

    • Manish Prakash

      Please go through all the blog and source code I have written on magento onepage checkout removing steps.
      What are asking for is possible, but I won’t be able to explain it in a reply to a comment.

      You need to understand the onestep checkout, its quite simple actually.

      • Yaboosa

        Thank you I’ll do it.

  • Hi Manish,

    Worked as a charm, thanks for this great solution!

    Roy

  • Kachagopal

    Hellio Manish,

    I can’t download the modules from site…

    What will be the issue??

    Even facebook login not work so please guide me how to download??

    • Manish Prakash

      What is the problem which your facing with facebook? Do you get any error?

      Regards

      Manish Prakash

      Co-Founder

      Excellence Technosoft Pvt Ltd

      +919717071555

      Visit Our Magento Blog @ http://www.excellencemagentoblog.com/

  • Narendra Kurapati

    Hi Manish,

    Its nice tutorial..

    I m trying to use this.. But i am getting following error “Mage_Checkout_Block_Onepage” not found. I dont know what is the problem.. Can you please help to get out from it? I am using Magento 1.8.

    thanks

  • cshensley

    Thank you for this blog! For this to work for me in v1.8.1, I had to put the following line at the bottom of the JS in onepage.phml:

    checkout.gotoSection(‘billing’, true);

    The billing panel would not show up for me otherwise.

  • Justin Veenis

    thanks for the tutorial.
    The guest checkout works perfect, but now when people are logged in the cant bet further than the billion information part. The button doesn’t want to work. Any tips/ fixes for this?

    Thanks

  • Vikas M. S.

    How will i retain the Billing Information page in here