Magento Onestep Checkout – Remove Payment Method Step

one-step-checkout
In this blog post, we will see how to remove the payment method step from onepage checkout.

This source code of this blog has been tested in magento 1.6 but should work on magento 1.4+, no core magento files have been changed including javascript files.
Removing the payment method step is very complex and require many files changes, so this blog would be lengthy again [:)]. Attached is source code for the module
Module Name: Checkout Remove Payment Source


As explained in the previous blog post, the basic idea of removing any step from checkout is to see a set a default value for that step, so that magento order processing runs smoothly. So when removing the payment method step, i have set the payment method “Zero Subtotal Checkout” with code “free” as the default payment method.
Magneto Zero Subtotal Payment Method

Magneto Zero Subtotal Payment Method

Now lets see step by step how to do it.

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', 'review');

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

So here as we can see i have removed the ‘payment’ step from the $stepCodes array.

Step2: PHTML and Layout Files

Next we need to make changes to these phtml files
1. checkout/onepage.phtml : To include our new javascript files
2. checkout/onepage/shipping_method.phtml: To change the shipping method javascript, so that after shipping step, review step shows up instead of payment step
3. checkout/onepage/progress.phtml: To remove payment method from progress sidebar
4. checkout/onepage/review/info.phtml: To make changes in submit order javascript
I am just pointing out changes done in these phtml files, for details you can download and see the module. Also there files have been overridden through layout xml inside the remove/ folder, so no changes made to core files. So in the file remove/checkout/onepage.phtml a new javascript file has been added for our custom javascript needs

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

and

var checkout = new Excellence(accordion,{

instead of

var checkout = new Checkout(accordion,{

In the file remove/checkout/onepage/shipping_method.phtml the change is

var shippingMethod = new ExcellenceShippingMethod('co-shipping-method-form', "<?php echo $this->getUrl('checkout/onepage/saveShippingMethod') ?>");

instead of

var shippingMethod = new ShippingMethod('co-shipping-method-form', "<?php echo $this->getUrl('checkout/onepage/saveShippingMethod') ?>");

In the file remove/checkout/onepage/progress.phtml
I have simple removed the Payment Method box.
In the file remove/checkout/onepage/review/info.phtml change made is

review = new ExcellenceReview('<?php echo $this->getUrl('checkout/onepage/saveOrder') ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements'));

instead of

review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder') ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements'));

So as we can see in the above changes, the major changes made are using of 3 new javascript classes Excellence,ExcellenceReview and ExcellenceShippingMethod. All these 3 javascript class are defined in removecheckout.js file.

Step3: Javascript Files

The source code the javascript file removecheckout.js is below

var Excellence = Class.create(Checkout, {
	initialize: function($super,accordion, urls){
		$super(accordion, urls);
		//New Code Addded
		this.steps = ['login','billing', 'shipping', 'shipping_method', 'review'];
	}
});
var ExcellenceShippingMethod = Class.create(ShippingMethod , {
	initialize: function($super,form, saveUrl){
		$super(form, saveUrl);
	},
	nextStep: function(transport){
        if (transport && transport.responseText){
            try{
                response = eval('(' + transport.responseText + ')');
            }
            catch (e) {
                response = {};
            }
        }

        if (response.error) {
            alert(response.message);
            return false;
        }
        checkout.setStepResponse(response);
    }
});
var ExcellenceReview = Class.create(Review,{
	initialize: function($super,saveUrl, successUrl, agreementsForm){
		$super(saveUrl, successUrl, agreementsForm);
	},
	save: function(){
        if (checkout.loadWaiting!=false) return;
        checkout.setLoadWaiting('review');
        var params = 'payment[method]=free';
        if (this.agreementsForm) {
            params += '&'+Form.serialize(this.agreementsForm);
        }
        params.save = true;
        var request = new Ajax.Request(
            this.saveUrl,
            {
                method:'post',
                parameters:params,
                onComplete: this.onComplete,
                onSuccess: this.onSave,
                onFailure: checkout.ajaxFailure.bind(checkout)
            }
        );
    }
});

There is not much to explain here except one important thing, in the ExcellenceReview class, i have put in the code

var params = 'payment[method]=free';

Here ‘free’ is the code of the payment method i am setting as default. So, if you setting some other payment method you need to put in that payment method’s code.

Step5: Controller

We need to override the default OnepageController.php and place in new code inside the saveShippingMethodAction() action. Here what we need to do is, set the payment method ‘free’ into the quote object when the shipping step is completed, and then redirect directly to the review step. So code to be added is

try{
					$data = array('method'=>'free');
					$result = $this->getOnepage()->savePayment($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.');
				}

Details are found in the module.

Step6: Override the Free Payment Method

This is a special step required, only when using the ‘free’ payment method only. By default in magento, the ‘Free’ payment is available only when order total is zero. So we need to change this in the Free Payment method class, so as to allow it in our case also.
So the class Mage_Payment_Model_Method_Free is overriden by Excellence_Remove_Model_Method_Free and the function

public function isAvailable($quote = null)
	{
		return true;
	}
1
is used instead of default
1
public function isAvailable($quote = null)
    {
        return parent::isAvailable($quote) && (!empty($quote))
            && (Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) == 0);
    }

After doing this everything should work fine and payment method will not show up in checkout

Magento Onepage Checkout  - Remove Payment Step

Magento Onepage Checkout - Remove Payment Step

Step7: Email

Next we need to remove the payment block from the email sent as well. This is very simple, open you email template files usually located at
1. app\locale\en_US\template\email\sales\order_new.html
2. app\locale\en_US\template\email\sales\order_new_guest.html
Find this code in the template files {{var payment_html}} and remove it.

That’s it, these are all the steps required.
  • http://twitter.com/jasonmillward jasonmillward

    Hi

    I’m trying to install this now and just wanted to conform where this bit of the script needs to go:

                   
                       
    Excellence_Remove_Block_Onepage              
               
     

    I have a config.xml file in app/code/local/Mage/page/etc/config.xml

    Is this the correct place?

    Many Thanks

    • Manish Prakash

      The best way to install this on your site is to download my module and upload it to your magento.
      But from your question, it seems like your are not using my module or you dont have your own module? Am i right?

  • http://twitter.com/jasonmillward jasonmillward

    Hi Manish

    I’m trying to use your module – just a little unsure where it needs to be uploaded and what amends ( if any ) I need to make in order to get it working.

    Once uploaded do I need to make any changes to the code apart from changing :

    var params = ‘payment[method]=free';I am using Check / Money order – what does this need to be changed to?Many ThanksJason

    • Manish Prakash

      After you upload the module you need to make change only to files
      the removecheckout.js and OnepageController.php
      payment[method]=free; need to make change here if you are using a different payment method. If your alright with the free payment method, then no more changes are needed. 

      • http://twitter.com/jasonmillward jasonmillward

        I’m using check / money order as payment method so what would this need chaging to in removecheckout.js?

        Thanks

        • Manish Prakash

          in the removecheckout.js you need to do
          var params = ‘payment[method]=checkmo';

          and in the Excellence_Remove_OnepageController you need to change
          $data = array(‘method’=>’free’);
          to 
          $data = array(‘method’=>’checkmo’);

          hopefully this should do the trick. let me know if you face any problems.

          • http://twitter.com/jasonmillward jasonmillward

            Hi Manish

            I seem to have everything installed ok but now I get a blank screen on checkout/onepage/

            The module seems to be working as the payment method has been removed from the progress bar on the right hand side, it’s just the main conent that is not showing.

            All the products are virtual so don’t have billing or postal details on teh check out page. Will this affect anything

            Thanks for your help with this

            Jason

          • Manish Prakash

            Do you get any error in log files or somewhere? blank screen means there is some php error. you need to find the error. read through my blog of error debugging maybe it will help to find the error.

          • http://twitter.com/jasonmillward jasonmillward

            I’ve got it working with simple products but I can’t get it workign wiht virtual products which I really need to.

            I see in onepagecontroller.php and removecheckout.js it checks to see if teh shipping mehtod is set.

            As the product is virtiual it doesnt have a shipping method so I can’t get past this step and review the order

            Can the references to shipping method be removed and which files would need to be edited to do this?

            Thanks

          • Manish Prakash

            I have uploaded the source code again, please check it now

          • http://twitter.com/jasonmillward jasonmillward

            Thanks I will give it a try and let you know how i get on.

            I really appreciate this Manish

          • http://twitter.com/jasonmillward jasonmillward

            I’m still not able to get past the billing information stage and review the order.

            Is there something I should look for in the updated code to make sure I have the correct version?

            Thanks

          • Manish Prakash

            It is working for me fine on my local system.

            Just check your Onepagecontroller.php for this line

            if(!$this->getOnepage()->getQuote()->isVirtual()){

            $method = ‘freeshipping_freeshipping';

            $result = $this->getOnepage()->saveShippingMethod($method);

            }

          • http://twitter.com/jasonmillward jasonmillward

            No it’s not in the latest version I downloaded. Where should I add it?

            Thanks

          • Manish Prakash

            It is not in this blog post.

            Your downloading source file this blog post right?
            http://www.excellencemagentoblog.com/magento-onestep-checkout-remove-payment-and-shipping-method-step

          • http://twitter.com/jasonmillward jasonmillward

            Thanks – no I didn’t download the source files from there! Its all working perfectly now

            I really appreciate the help you have given me in this. It’s much appreciated.

            Is there a way I can contact you privately as I would like to put a proposal to you?

            Many Thanks
            Jason

          • Manish Prakash

            Yes you can contact me. Please use the form in the contact us. Then I will get an email

          • Mohsinrafiq

            what should i use for creditcard?

          • jeethendar

            i have 1 problem regarding in checkout page so help me

          • jeethendar

            are you their

  • Michael Fanini

    I succeeded in the remove shipping step method.

    Now I want to plug the remove payment step method so that I can go from adresses to directly the review.

    Do you think it is possible?

    • Manish Prakash

      Yes its 100% possible, just go through my Removing Payment blog closely and copy the code to the appropriate files.  

      • Michael Fanini

        Okay thanks.

        But as I don’t use the shipping method anymore thanks to your other tutorial.
        Do I have for example to modify files as shipping_method.phtml? Or instead modify shipping.phtml or billing.phtml in the same way?
        Do I have also to put this function in js :
        var ExcellenceShippingMethod = Class.create(ShippingMethod , {
            initialize: function($super,form, saveUrl){
                $super(form, saveUrl);
            },
            nextStep: function(transport){
                if (transport && transport.responseText){
                    try{
                        response = eval(‘(‘ + transport.responseText + ‘)’);
                    }
                    catch (e) {
                        response = {};
                    }
                }
         
                if (response.error) {
                    alert(response.message);
                    return false;
                }
                checkout.setStepResponse(response);
            }
        });or remove it or modify it also to fit with shipping and not shipping method?Thanks in advance,Michaël.

         

        • Manish Prakash
          • Michael Fanini

            Just went throw all the tutorial after succes with previous tuto (skip shipping method step).

            I’ve then made a mix between the 2 tutos.

            But now when I want to continue after billing infos, nothing happens.

            Don’t you think I have to modify a bit this tuto to fit my needs ?

          • Manish Prakash

            can you send me link to your site i will check it out

          • Michael Fanini

            1. here is the link : http://91.121.6.71/magento-1.5.1.0

            it works as a flashsale site so you have to be logged in.
            Then go to a product in an active flash sale. Click add to cart and you’ll be redirected to checkout process.
            Sorry site is in production just developped some modules. So no design.

            2. I’m following you on twitter but I’m unable to download your sources for this tuto.
            Tried several times but does not work.

             

          • Manish Prakash

            OK.

            1. can you give me a login to view the checkout page?
            2. Regarding the twitter, you dont see the download link? even after you authenticate it still doesnt say ur following?

          • Michael Fanini

            http://91.121.6.71/magento-1.5.1.0

             1. mail : mo.mo@ouep.com / pwd : ouepouep
            2. Everything is ok, I’m following (under nick : mika2na) and all but still unable to download.

          • Manish Prakash

            please check now if your able to get the download link? i have added your name to the whitelist

          • Michael Fanini

            download successfull ! Going to try it !

            I give you feedback soon.

            Thanks a lot for all Manish.

          • Michael Fanini

            Just done the copy and paste step. In fact I had done good job with just the tuto.

            But still nothing happens after clicking on continue after billing infos.

            Considering I don’t have anymore, the shipping method step thanks to the previous tuto :

            1 . Are my steps the following [‘login’,’billing’, ‘shipping’,  ‘review’];
            instead of this steps : [‘login’,’billing’, ‘shipping’, ‘shipping_method’, ‘review’];

            2 . In the js, should I write a “var ExcellenceShipping” function  instead of “var ExcellenceShippingMethod ” ?

            3 . Do we really need to override saveShippingMethodAction().
            Instead shouldn’t we try replacing the code already overrided in saveShippingAction() and saveBillingAction() (done in previous tuto) by the code you proposed in saveShippingMethodAction().

             

          • Manish Prakash

            I think it would be much simpler, if i just upload source code for removing both payment and shipping method. So just wait, i will upload it soon.

          • Michael Fanini

            Thisi is great.
            Thank you Manish.

          • Manish Prakash

            i have added the module to this blog post

            http://www.excellencemagentoblog.com/magento-onestep-checkout-remove-payment-and-shipping-method-step

            let me know if there is any problem

          • Manish Prakash

            Also once after downloading the source code. because there are many files which are in the source code but not explain in this blog. P.S the login password u sent didnt work

          • Michael Fanini

            I’m sorry…

            Try this
            moi@ouep.com
            pwd : ouioui

          • jeethendar

            hi

  • Patchlawler

    I have a question regarding this module in the file info.phtm there is the following code
    getChildHtml(‘button’) ?>

    I’m using 1.4.2.0 and the button is contained within /onepage/review.phtml not onepage/review/info.phtml

    So at present there is no button rendered. Any ideas should I just copy the code for the button
    <button type="submit" title="__(‘Place Order’) ?>” class=”button btn-checkout” onclick=”review.save();”>__(‘Place Order’) ?>
    from review.phtml into info.phtml ?

    • Manish Prakash

      In magento 1.4 the button code is directly placed in review.phtml file line 34

      <button type="submit" title="__(‘Place Order’) ?>” class=”button btn-checkout” onclick=”review.save();”>__(‘Place Order’) ?>

      in my module i have not made any changes to review.phtml file, i have just changed the info.phtml file.

      So the button show up in the review.phtml itself. 

  • naga

    hi
    iam new to magento
    when iam adding coupon in discount coupons  textbox in onestepcheckout , it is applying but in totals it is taking last added coupon amount.

    • Manish Prakash

      There must be some problem in your magento theme. Do you get the same problem in default magento theme as well?

  • http://twitter.com/gleisilva Gleice Silva

    Hi there, so I have just implemented the source code you provide on here but for some reason on the checkout page once I click ‘continue’ under billing information nothing happens… any thought to fix it?

    If not, what do I need to do to ‘undo’ the source codes I did? I’m using magento 1.6.1.0 btw

    • http://twitter.com/gleisilva Gleice Silva

      Nevermind, issue fixed :)

      • Troy

        How did you fix this issue?

      • imane

        how did you resolve that help me pleaaaaase i have the same problem

      • Mohsinrafiq

        Same problem here…. Any Help?

  • http://twitter.com/pantzan Pantelis Zanias

    Hello, 
    I downloaded ans installed but when i am going to checkout doesn’t check my custom payment merthod that i setup and stack in last step.http://test.cartridgeworld.gr/checkout/onepage/

    Thanks

  • garethdaine

     Any ideas on this Manish? Thanks.

  • http://www.phpzag.com/ laeeq khan

    really nice article

  • Mariya Davis

    Hi Manish,

    I followed your steps and download your module and did the below:

    i did the step1 in app/code/core/Mage/Checkout/etc/config.xml file

    1./app/design/frontend/default/default/layout/remove.xml
    in server : app/design/frontend/base/default/layout/remove.xml

    2.app/design/frontend/default/default/template/remove/
    in server : app/design/frontend/base/default/template/remove

    3.app/code/local
    in server : app/code/local

    4.app/etc/modules/Excellence_Remove.xml
    in server : app/etc/modules/Excellence_Remove.xml

    5.skin/frontend/default/default/js/removecheckout.js
    in server : skin/frontend/base/default/js/removecheckout.js
    Then i flush the cahe in admin panel.And tabke add the proudct in to cart by clicking on the button Add to Cart.then i got an 404 error:`
    Whoops, our bad…

    The page you requested was not found, and we have a fine guess why.

    If you typed the URL directly, please make sure the spelling is correct.
    If you clicked on a link to get here, the link is outdated.

    What can you do?
    Have no fear, help is near! There are many ways you can get back on track with Magento Store.

    Go back to the previous page.
    Use the search bar at the top of the page to search for your products.
    Follow these links to get you back on track!
    Store Home | My Account

    `
    How can i solve this?What is the mistake in code?My magento version is 1.7.0.0
    Anybody have any idea about this?all helps are appreciatable.
    I need a the solution immediately.Plz help me ……

  • Mohsinrafiq

    what is the path for file
    opcheckout.js?

  • http://www.facebook.com/thuongln Xman Classical

    Hello, Plz tell me how to Removing Step 2 “Shipping Information” from Magento!

    Thanks so much!

  • http://www.facebook.com/onacadrianro Bobo Bob

    Hello,
    I installed the extension and at the checkout (it removed the payment) when i press the “Continue” button, doesn’t do nothing… what can be the problem?
    thanks

    • Keshav yadav

      Same Problem please help ASAP

  • iLoveMage

    One of the powerful module to enhance your customer experience by making your 6 steps checkout into 1 single step. Best Selling one step checkout for magento community, professional and enterprise version

    Thanks
    iLoveMage

  • heaven78

    Hi Manish,
    first thanks for your extension. I tested it with CE 1.7.0.2 and i recognized that instead of

    app/design/frontend/default/default/
    skin/frontend/default/default/

    the folder structure should be:

    app/design/frontend/base/default/
    skin/frontend/base/default/

    All other things run smooth.
    Keep on your good work!

  • David Bania

    For magento 1.8.x I had to update the javascript in info.phtml to include the Form Key:

    //<![CDATA[

    review = new ExcellenceReview('getUrl(‘checkout/onepage/saveOrder’, array(‘form_key’ => Mage::getSingleton(‘core/session’)->getFormKey())) ?>’, ‘getUrl(‘checkout/onepage/success’) ?>’, $(‘checkout-agreements’));

    //]]>

  • Keshav yadav

    I installed the extension and at the checkout (it removed the payment)
    when i press the “Continue” button, doesn’t do nothing… what can be
    the problem?
    thanks