Page 1 of 1

[SOLVED - 1.4.6]Redirect to login from add to cart

Posted: Mon Apr 26, 2010 3:07 pm
by bcit
Hello team, Can you guide me how to redirect into the 'login page' when someone clicks the “add to cart” button if that person not signed in already? I am using opencart 1.4.6, Many thanks.

Re: [1.4.6]Redirect to login from add to cart

Posted: Mon Apr 26, 2010 5:51 pm
by kedgetech
Mate any Specific reason why you want to do this ? There is an option in OC to restrict guest checkout i.e only registered users would be able to check out the order.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 1:20 am
by bcit
kedgetech wrote:Mate any Specific reason why you want to do this ? There is an option in OC to restrict guest checkout i.e only registered users would be able to check out the order.

venkat@morrisnphilip
Thanks venkat for your reply. Yes, I know about the guest checkout & already disabled it. I want the redirect to login option simply because I want to approve the new customer accounts before they sign in. So that I can prevent them from adding the products to shopping cart before they get approved. Otherwise customers spend the time to add the items into cart, then unable to checkout/submit the products due to approval issue & their effort will be wasted. Please let me know if you can help me to add couple of lines for login check in the add to cart page. Your help will be appreciated.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 7:23 am
by kedgetech
Mate give it a try. Mind you I did not test it, just scribbled away so there may be spelling issues/ syntax errors or other implications.

File needs to change (catalog\controller\module\cart.php)

<?php
class ControllerModuleCart extends Controller {
protected function index() {

if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = HTTPS_SERVER . 'index.php?route=account/account';

$this->redirect(HTTPS_SERVER . 'index.php?route=account/login');
}

$this->language->load('module/cart');

$this->load->model('tool/seo_url');

Other option you may think off is. Do not display prices to them and show a message you need to login to see prices not sure if that helps.

Let me know how you go.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 7:30 am
by kedgetech
Looks like $this->session->data['redirect'] = HTTPS_SERVER . 'index.php?route=account/account';

Try remove the above and try.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 7:57 am
by bcit
kedgetech wrote:Looks like $this->session->data['redirect'] = HTTPS_SERVER . 'index.php?route=account/account';

Try remove the above and try.

venkat@morrisnphilip
Thanks venkat for your reply. I have tried as you suggested (both codes) but unfortunately didn’t work, getting the server error 500. Have you got any other ideas to do this trick? Much appreciated help.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 7:20 pm
by kedgetech
Tried partially works (opens in another iFrame sort of thing). I guess you should get some PHP developer to help you out.

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 27, 2010 9:54 pm
by Qphoria
1. EDIT: catalog/view/theme/YOURTHEME/template/module/cart.tpl

2. FIND:

Code: Select all

$('#add_to_cart').click(function () {
3. AFTER, ADD:

Code: Select all

islogged = '<?php echo $this->customer->isLogged(); ?>';
		if (!islogged) {
			window.location.replace("index.php?route=account/login");
			return;
		}

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Apr 28, 2010 1:02 am
by bcit
Thanks a lot Qphoria. I have added the code in the cart.tpl page exactly as you suggested but the add to cart click functionality still not redirecting to login page instead just work as normal (no error returned). Please see the code below: (cart.tpl- from line number 31)

Code: Select all

$('#add_to_cart').click(function () {
	islogged = '<?php echo $this->customer->isLogged(); ?>';
      if (!islogged) {
         window.location.replace("index.php?route=account/login");
         return;
      }
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#product :input'),
			success: function (html) {
				$('#module_cart .middle').html(html);
			},
Please let me know if I did something wrong / missed any brackets and semicolons. Q, your support in this matter is very much appreciated.

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Apr 28, 2010 2:36 am
by Qphoria
Works perfectly for me
Do you have a link to your site I can see?

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Apr 28, 2010 5:50 am
by kedgetech
Q - thanks mate

bcit - Try the below if php redirect works. replace yourinstalldetail with actual store details.

islogged = '<?php echo $this->customer->isLogged(); ?>';
if (!islogged) {
<?php
header("Location: http://<yourinstallationdetail>/index.php?route=account/login");
exit;
?>
}

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed May 05, 2010 1:45 am
by bcit
Qphoria wrote:Works perfectly for me
Do you have a link to your site I can see?
Thank you Qphoria & venkat@morrisnphilip & apologies for my bit late response (sorry, have been travelling for a week).
Qphoria, now your script works great for me (I was using xampp in local machine, not yet uploaded into the production server). Thanks a lot for both of you guys.

Re: [1.4.6]Redirect to login from add to cart

Posted: Thu Sep 23, 2010 8:20 pm
by Boekel
How do I change this using 1.4.8b?

Re: [1.4.6]Redirect to login from add to cart

Posted: Fri Sep 24, 2010 6:56 pm
by dramony
is there a way to redirect the user to previous page(ex: product page) after login?

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Nov 17, 2010 10:54 am
by ahhcrap
dramony wrote:is there a way to redirect the user to previous page(ex: product page) after login?
If you are asking how to redirect the customer back to the page they were on instead of the account page, I'd like to know that too. Any thoughts anyone? I'm a noob!

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 14, 2020 9:07 am
by nightwing
Count me in!
ahhcrap wrote:
Wed Nov 17, 2010 10:54 am
dramony wrote:is there a way to redirect the user to previous page(ex: product page) after login?
If you are asking how to redirect the customer back to the page they were on instead of the account page, I'd like to know that too. Any thoughts anyone? I'm a noob!

Re: [1.4.6]Redirect to login from add to cart

Posted: Tue Apr 14, 2020 9:15 am
by straightlight
seanstorm100 wrote:
Tue Apr 14, 2020 9:07 am
Count me in!
ahhcrap wrote:
Wed Nov 17, 2010 10:54 am
dramony wrote:is there a way to redirect the user to previous page(ex: product page) after login?
If you are asking how to redirect the customer back to the page they were on instead of the account page, I'd like to know that too. Any thoughts anyone? I'm a noob!
If you're still referring to OC v3.x releases, this validation has already been integrated since quite sometime from your catalog/controller/account/login.php file:

Code: Select all

// Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
			if (isset($this->request->post['redirect']) && $this->request->post['redirect'] != $this->url->link('account/logout', '', true) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
				$this->response->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
			} else {
				$this->response->redirect($this->url->link('account/account', '', true));
			}
If it doesn't redirect to the previous page where the customer was previously at this point, it means the previous page does not use the redirect key so for Opencart to know where to redirect too other than the account/account route.

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Apr 15, 2020 10:17 pm
by nightwing
Hey Straightlight - Yes I am referring to the latest version. All logon goes to the Account Page.
straightlight wrote:
Tue Apr 14, 2020 9:15 am
seanstorm100 wrote:
Tue Apr 14, 2020 9:07 am
Count me in!
ahhcrap wrote:
Wed Nov 17, 2010 10:54 am


If you are asking how to redirect the customer back to the page they were on instead of the account page, I'd like to know that too. Any thoughts anyone? I'm a noob!
If you're still referring to OC v3.x releases, this validation has already been integrated since quite sometime from your catalog/controller/account/login.php file:

Code: Select all

// Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
			if (isset($this->request->post['redirect']) && $this->request->post['redirect'] != $this->url->link('account/logout', '', true) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
				$this->response->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
			} else {
				$this->response->redirect($this->url->link('account/account', '', true));
			}
If it doesn't redirect to the previous page where the customer was previously at this point, it means the previous page does not use the redirect key so for Opencart to know where to redirect too other than the account/account route.

Re: [1.4.6]Redirect to login from add to cart

Posted: Wed Apr 15, 2020 10:27 pm
by straightlight
Then, it means based on the extension theme you are using, the redirect key has not been added to the HTML form in the page you are addressing about. In addition, you are posting in the v1.5x releases. If you're using the latest release, please create a new topic in the General Support section of the Opencart v3.x in the future.

Re: [1.4.6]Redirect to login from add to cart

Posted: Thu Apr 16, 2020 1:13 am
by nightwing
OK noted.
straightlight wrote:
Wed Apr 15, 2020 10:27 pm
Then, it means based on the extension theme you are using, the redirect key has not been added to the HTML form in the page you are addressing about. In addition, you are posting in the v1.5x releases. If you're using the latest release, please create a new topic in the General Support section of the Opencart v3.x in the future.