0

I wanted to remove the login step from Magento's default checkout and making users to be redirected to the default login page, it doesn't make sense having 2 logins forms.

Is that possible? Important: after logging in, user needs to be redirected to checkout after that instead of account page or whatever page else...

2

This is not something you can achieve with default Magento. You could make this work with just a simple observer for the event controller_action_predispatch_checkout_onepage_index. In that observer, you could do a check if the user is checked in or not. If not, you can redirect the user to the account/login page.

You will need a custom module for this. This code should get you on the right track:

app/modules/Namespace_CheckoutLoggedin.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_CheckoutLoggedin>
            <active>true</active>
            <codePool>local</codePool>
        </Namespace_CheckoutLoggedin>
    </modules>
</config>

app/code/local/Namespace/CheckoutLoggedin/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_CheckoutLoggedin>
            <version>1.0.0</version>
        </Namespace_CheckoutLoggedin>
    </modules>
    <global>
        <models>
            <namespace_checkoutloggedin>
                <class>Namespace_CheckoutLoggedin_Model</class>
            </namespace_checkoutloggedin>
        </models>
        <events>
            <controller_action_predispatch_checkout_onepage_index>
                <observers>
                    <checkout_customer_loggedin>
                        <class>namespace_checkoutloggedin/observer</class>
                        <method>checkCustomerLoggedin</method>
                    </checkout_customer_loggedin>
                </observers>
            </controller_action_predispatch_checkout_onepage_index>
        </events>
    </global>
</config>

app/code/local/Namespace/CheckoutLoggedin/Model/Observer.php

<?php

class Namespace_CheckoutLoggedin_Model_Observer
{
    public function checkCustomerLoggedin(Varien_Event_Observer $observer)
    {
        if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
        }
    }
}

The code is untested, so maybe it doesn't work out-of-the-box, but this should give you an idea on how to fix this.

  • It worked man! Sorry, I'm just the front guy. As I have no knowledge with mvc architecture, I don't know how to do those stuff yet. Firstly, your code on Observer.php had generated this error: "ERR (3): Recoverable Error: Argument 1 passed to Custom_CheckoutLoggedin_Model_Observer::checkCustomerLoggedin() must be an instance of Varien_Observer, instance of Varien_Event_Observer". After I removed this "Varien_Observer $observer", Magento hasn't log an error anymore. – joaogdesigner Apr 8 '17 at 7:28
  • Glad I could help. Changed it in my answer – Arjen Miedema Apr 8 '17 at 7:30
2

I already found out what I was looking for, just added the following php code on "onepage.phtml":

if (!$this->helper('customer')->isLoggedIn()) {
    // Add a message that will display on the login page
    Mage::getSingleton('core/session')->addError('Please log in or create an account to checkout.');

    // Create the redirection
    header("Location: " . $this->helper('customer')->getLoginUrl());
    exit();
}

It worked like a charm, so that way allow us to skip unnecessary work to customize and have 2 logins. Hope this helps everyone!

0

System menu>Configuration>Checkout button in the Sales section on the left>Checkout Options panel on the right. After you expand the Checkout Options panel you'll see a drop-down menu Allow Guest Checkout; just set it to No.

Try this.Hope this will work.

  • That option is already set to "No" and it only makes difference by allowing users to register themselves on the checkout page, I mean, the button "Register" takes the user to the default register page as expected, but that is not happening with login. Instead Magento showing the one page checkout with a form, the user should be taken to the "/customer/account/login" page and use the login form in that page and not on checkout. I'm not sure if a redirect would work correctly, so I would like to hear from you if there is some valid and safe option, without "compromise" Magento functionality. – joaogdesigner Apr 7 '17 at 4:29

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.