How to make Magento’s checkout in a one page

magento_logo

Dealing with Magento we’ve noticed there’s with 6 steps checkout. Magento is not very flexible to customize so 1 step there’s 1 step checkout plugins you can buy for this. Here’s what I’ve found about that.

Basicaly a page can be shown in Magento using simple Core_Template type. Basically all code is set inside the .phtml file so it can be shown on every possible page or block, meaning it’s object independent, no inheritance. Something you can call from with your layout files like


If you have such special requirements for your site below is the code that you can place on whatever file you wish and include it yout tempalte as block type core/template.

$checkout = Mage::getSingleton(’checkout/type_onepage’);
/*
* One page checkout consists of following steps
* (1) Customer login method aka Checkout method
* (2) Billing information (address)
* (3) Shipping information (address)
* (4) Shipping method
* (5) Payment information
* (6) Order review, in short: DO THE ORDER
*/

//STEP(1)
$checkout->saveCheckoutMethod(’guest’);

//STEP(2)
$checkout->saveBilling($billingAddress, false);

//STEP(3)
$checkout->saveShipping($shippingAddress, false);

//STEP(4)
$checkout->saveShippingMethod(’flatrate_flatrate’);

//STEP(5)
$checkout->savePayment(array(’method’=>’checkmo’));

//STEP(6)
/*
* $checkout->saveOrder() returns array holding empty object
* of type Mage_Checkout_Model_Type_Onepage
*/
$checkout->saveOrder();

And here is the example of how the $address variables are supose to look

[billing] => Array
(
[address_id] => 5
[firstname] => Branko
[lastname] => Ajzele
[company] => Surgeworks
[email] => ajzele@somemail.com
[street] => Array
(
[0] => Address part 1
[1] => Address part 2
)

[city] => Osijek
[region_id] =>
[region] =>
[postcode] => 31000
[country_id] => HR
[telephone] => 0038531000331
[fax] => 0038531000332
[customer_password] =>
[confirm_password] =>
[save_in_address_book] => 1
)

[shipping] => Array
(
[address_id] => 6
[firstname] => Ivan
[lastname] => Weiller
[company] => Surgeworks
[street] => Array
(
[0] => Address part 1
[1] => Address part 2
)

[city] => Osijek
[region_id] =>
[region] =>
[postcode] => 31000
[country_id] => HR
[telephone] => 0038531000333
[fax] => 0038531000334
[save_in_address_book] => 1
)

And you can wrapp the above checkout code into something like

if($this->getRequest()->getParam(’submitCustomCheckout’))
{
//Checkout code from above…
}

Where ubmitCustomCheckout is the name of the submit button or submit input field. To extract addresses you can use something like

$billingAddress = $this->getRequest()->getParam(’billing’);
$billingAddress['use_for_shipping'] = 0;
$shippingAddress = $this->getRequest()->getParam(’shipping’);

That’s it. Simple, predefined checkout by whitch order can be make on one click.

6 thoughts on “How to make Magento’s checkout in a one page

  1. Tony O'connell

    Thanks for that. Had planned to try to solve this problem sometime soon. It’s obvious from your few posts on your blog that you’re very good at what you do. Best wishes. Tony

    P.S. do you know that the bar at the bottom of your site is almost invisible (to me anyway)? Was looking for your RSS feed and only found it when I was writing this comment.

    Reply
  2. Isy

    Could you modify and show the code using Authorize.Net instead of Check or Money Order? Your help is really appreciated.

    Thanks!

    Reply
  3. ron

    I really don’t get it right, but I suppose that you are explaining how to transform the 6 steps checkout to a single step checkout. Could you please mention, where to put the code you are showing here. For newbies like me, it is impossible to guess where to put each code window you are showing.
    Hope you understand…

    Reply
  4. Jeremy

    Hi, I know this post has not been commented on in quite some time, but I stuck trying to get this working. I get an error when I try and run this. My code looks like

    $email = 'email@email.com';
    $customer = Mage::getModel('customer/customer');
    $customer->setWebsiteId($model->getWebsite()->getId());
    $customer->loadByEmail($email);
    Mage::getModel('customer/session')->loginById($customer->getId());

    $checkout = Mage::getModel('checkout/type_onepage');

    print_r($checkout->getCheckoutMethod());

    The error I get is “Fatal error: Cannot use object of type Mage_Checkout_Model_Type_Onepage as array in /home/leesavo/public_html/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php on line 338”

    Any thoughts or suggestions would be greatly appreciated. Thanks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *