0

i add this condition on the Proceed to Checkout button:

<?php if ($this->isPossibleOnepageCheckout() && Mage::getSingleton('customer/session')->isLoggedIn()):?>
    <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Proceed to Checkout')) ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo $this->getCheckoutUrl() ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php else: ?>
    <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Proceed to Checkout')) ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo Mage::getUrl('customer/account/login'); ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php endif?>

So when a user is not login on my store will be redirected to Login / Register page. I made a custom function to redirect the customers after register to checkout page if the was in Shopping Cart else redirect to My Account. But I don't know what is wrong, because now after register I am redirect only to My Account. So I want to redirect customer after registration to the Checkout page if the customer was in the Shopping Cart else to My Account. This is my function:

   public function customerRegistration(Varien_Event_Observer $observer)
   {
      if(Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1){
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('onestepcheckout/index'));
            Mage::app()->getResponse()->sendResponse();
            exit;
         }
    else
        {
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
         Mage::getSingleton('core/session')->setIsFromCart('0');
    Mage::getSingleton('core/session')->setIsFromCheckout('0');
   }

and this is my observer in the config.xml

    <customer_register_success>
        <observers>
          <customerredirect>
            <class>customerredirect/observer_customer</class>
            <method>customerRegistration</method>
          </customerredirect>
        </observers>
    </customer_register_success>

Update:

i have found something like this to save the last x Url's in array, maybe someone can tell me how I can adapt this for my code? Thank you

$urlHistory = (array) Mage::getSingleton('core/session')->getMyUrlHistory();
while (is_array($urlHistory) && count($urlHistory) > 3) {
    array_shift($urlHistory);   
}
$urlHistory[] = Mage::helper('core/url')->getCurrentUrl();
Mage::getSingleton('core/session')->setMyUrlHistory($urlHistory);

Anyone?

  • Where do you set "setIsFromCart" and "setIsFromCheckout" ? – Phoenix128_RiccardoT Mar 5 '16 at 11:32
  • I am on skype I can show you – Robert Mar 5 '16 at 11:37
1

This may depend on different reasons and maybe more of one, so make different tests:

First check:

Make sure you have implemented the form_key in your login page

Second check:

Make sure you configured to not redirect to dashboard:

Admin > System > Configuration > Customer Configuration > Login Options > Redirect Customer to Account Dashboard after Logging in

Third Option:

Disable your observer and try adding an hidden input field in your registration page just after the form tag opening (template file is register.phtml):

<input type="hidden" name="success_url" value="<?php echo Mage::getUrl('onestepcheckout/index', array('_secure'=>true)) ?>" />

This is according to _redirectSuccess method in Mage_Core_Controller_Varien_Action.

You will have to add the if condition you used in your controller of course. According to your code:

...
<?php if(Mage::getSingleton('core/session')->getIsFromCart() == 1 || Mage::getSingleton('core/session')->getIsFromCheckout() == 1): ?>
    <input type="hidden" name="success_url" value="<?php echo Mage::getUrl('onestepcheckout/index', array('_secure'=>true)) ?>" />
<?php else: ?>
    <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<?php endif; ?>
...
  • Unfortunately no one solution not work – Robert Mar 5 '16 at 12:11
  • Just tried on my local installation and works fine. Make sure you do not have two "success_url" fields in your register.phtml – Phoenix128_RiccardoT Mar 5 '16 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.