views:

1041

answers:

3
+3  Q: 

Magento checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it?

I'm working on a payment module and have a sort of "cancel" action that i would like to return the user to the step in checkout where you choose the payment method.

I currently return the user to the first step of the checkout like so:

$this->_redirect('checkout/onepage', array('_secure'=>true));

Another issue with this is that i does not work all the time, in certain browsers i'd really not like to name this sort of works "sometimes". Is that something that is known and/or commonly accepted? I have very little actual information regarding this, but i've had complaints from customers about this behaviour. They generally won't give me any specifics so it's kind of a dead end.

+2  A: 

Sorry for not being clear. Open the template for the onepage checkout page. It is app/design/frontend/default/default/template/checkout/onepage.phtml In the file add

<?php 
//if (your cancel condition) 
{ 
echo 
'<script type="text/javascript"> 
checkout.gotoSection(\'checkout-step-review\'); 
</script>'; 
}
?>

This will take the user the to the step you need. You have to decide the condition(s) under which the user is taken to the step.

Rick J
Not sure i follow you there.. Could you explain?
Peter Lindqvist
What page are you referring to, and how do i do that in the controller that redirects to the checkout page?
Peter Lindqvist
Thanks, now i understand perfectly!
Peter Lindqvist
this alone did not work. i also had to load the different steps and save the data.
Peter Lindqvist
+1  A: 

Rick is referring to the fact the 'steps' in the checkout are a not RESTful, but Ajaxified steps, they are all on the same page, the vertical accordion is, in fact, just a set of divisions manipulated by a javascript function. You'll need to set the javascript to the proper step as he stated.

4.669201
It sounds as if there is no "standardized" way to land the user on a certain step. Is that a correct assumption?
Peter Lindqvist
+2  A: 

checkout/onepage.phtml:

In PHP

$step = Mage::app()->getRequest()->getParam('step');
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');

if (($step) && (in_array($step,$stepCodes)) && ($this->getActiveStep() == 'billing')) {
    $checkout = Mage::getSingleton('checkout/type_onepage');
    $checkout->saveBilling(Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->toArray(),false);
    $checkout->saveShipping(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->toArray(),false);
    $checkout->saveShippingMethod(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod());
    $activestep = Mage::app()->getRequest()->getParam('step');
}
else 
if($this->getActiveStep()) {
    $activestep = $this->getActiveStep();
}

In javascript

accordion.openSection('opc-<?php /* edit */ echo $activestep; ?>');
Peter Lindqvist
I do suspect that loading the checkout could be simplified considering that the customer already has a quote prepared. But this is the way that i got it to work. If anyone can improve from it, please!
Peter Lindqvist