Magento - "go to check" button to go to the login page if you are not logged in

When a user who is not logged in (anonymously) clicks Proceed to checkout , I want them to be sent to the login page. Then, after they have logged in or registered, they should be returned to the upload page.

I am using onepage checkout, which has an login section that you are not logged into, but privileges that do not want this.

Initially, I started the checkout.xml change path to have the following meanings:

 <customer_logged_in> <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label"> <label>Payment Methods Before Checkout Button</label> <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/> </block> </customer_logged_in> <customer_logged_out> <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label"> <label>Payment Methods Before Checkout Button</label> <block type="checkout/onepage_link_not_logged_in" name="checkout.cart.methods.onepage" template="checkout/onepage/link_not_logged_in.phtml"/> </block> </customer_logged_out> 

And link_not_logged_in.phtml :

 $this->getLoginUrl(); 

but it didn’t even pull my new phtml file, and I’m not even sure that it will lead me to the verification page after. Any articles or help are largely received.

+4
source share
3 answers

Go to your admin site. Click Stores . Go to Configuration Sales Checkout Checkout Options and set Allow Guest Checkout to No.

edit

Open app/design/frontend/base/default/template/checkout/onepage.phtml . Put the following code at the very top of the file:

  <?php if (!$this->helper('customer')->isLoggedIn()) { header("Location: /customer/account/login/"); exit(); } ?> 

Finally, set Custom Login Redirect to https://marketplace.magento.com/magehit-magehit-customloginredirect.html . Go to Admin → System → Configuration → Clients → Login redirection. Set it to checkout/cart

Everything is ready! I checked this and it does what you described. I usually follow all the various steps to complete the revisions presented in these extensions, but you can see this by going to app / code / local and looking at the extension code.

+7
source

You do not have the Mage / Checkout / Block / Onepage / Link / Not / Logged / In.php block that you are trying to access

If you create this link directly in checkout / onepage / link_not_logged_in.phtml , so you should use this code

 <customer_logged_out> <block type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label"> <label>Payment Methods Before Checkout Button</label> <block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link_not_logged_in.phtml"/> </block> </customer_logged_out> 

Thus, your block type should be the same as in the standard

0
source

The answer from seanbreeden pointed me in the right direction, but I think there is additional information and some improvements that can be made.

You need to add a redirect from the statement to the login page. The easy place for this is in the statement template. If you use single page validation and default design, it will be app/design/frontend/default/default/template/remove/checkout/onepage.phtml . Just add this code at the beginning of this template (inside the <?php ?> Tags).

 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(); } 

Pay attention to the use of getLoginUrl() , this will allow Magento to redirect to the verification page after the user logs in.

0
source

Source: https://habr.com/ru/post/1395755/


All Articles