Question

I've edited tm/firecheckout/checkout/link.phtml to display a modal window in shopping cart when the user is not logged in.

I've set it up that when a user enters the wrong credentials (setBeforeAuthUrl) it stays on /checkout/cart/. Otherwise the user is redirected to /firecheckout/.

This is the code:

<!-- Show login/register modal window if user is not logged in -->
<?php if ( $this->isPossibleFireCheckout() ): ?>
<?php if ( ! Mage::getSingleton( 'customer/session' )->isLoggedIn() ): ?>
    <?php
    // If credentials are invalid, stay on page. Otherwise send to checkout.
    Mage::getSingleton( 'customer/session' )->setBeforeAuthUrl( Mage::getUrl( 'checkout/cart' ) );
    Mage::getSingleton( 'customer/session' )->setAfterAuthUrl( Mage::getUrl( 'firecheckout' ) );
    ?>
    <button onclick="toggleCheckoutModal()" id="toggleCheckoutModal" type="button"
            class="button btn-proceed-checkout btn-checkout<?php if ( $this->isDisabled() ): ?> no-checkout<?php endif; ?>">
        <span><span><?php echo $this->__( 'Proceed to Checkout' ) ?></span></span>
    </button>
    <div id="checkoutModal" class="checkoutModal">
        <div id="closeCheckoutModal" class="closeCheckoutModal">X</div>
        <?php echo $this->getLayout()->createBlock( 'customer/form_login' )->setTemplate( 'persistent/customer/form/login.phtml' )->toHtml(); ?>
    </div>
<?php else: ?>
    <button type="button" title="<?php echo $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 endif ?>
<?php endif ?>

What I want to do is show a error-message (using the global-messages div) after a user has entered wrong credentials and is redirected back to the checkout/cart/ page. Is this possible?

I've googled around, but can't seem to find anything related to this.

Was it helpful?

Solution

Yes its certainly possible.

Basically you want to convert the login form request/response to an AJAX call, with a success message to set the page location... but a failure to display a warning message (within the lightbox).

The most important part is creating your own controller response (subclass) that is able to handle the AJAX form request with your customization... you can't use the default from Mage_Customer_AccountController::loginPostAction(), you need to modify it to:

  1. Check for an AJAX request (if not ajax, then call parent behavior)
  2. Instead of adding to the session error, return the error as part of the ajax response
  3. Redirect to your checkout page on success instead of the default _loginPostRedirect()

Also depending on how you setup the AJAX form, the form data may not actually be in a POST format.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top