Post by bcit » Mon Apr 26, 2010 3:07 pm

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.

Newbie

Posts

Joined
Sat Apr 10, 2010 12:52 pm

Post by kedgetech » Mon Apr 26, 2010 5:51 pm

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.
Last edited by kedgetech on Sun Aug 22, 2010 10:40 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by bcit » Tue Apr 27, 2010 1:20 am

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.

Newbie

Posts

Joined
Sat Apr 10, 2010 12:52 pm

Post by kedgetech » Tue Apr 27, 2010 7:23 am

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.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by kedgetech » Tue Apr 27, 2010 7:30 am

Looks like $this->session->data['redirect'] = HTTPS_SERVER . 'index.php?route=account/account';

Try remove the above and try.
Last edited by kedgetech on Sun Aug 22, 2010 10:40 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by bcit » Tue Apr 27, 2010 7:57 am

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.

Newbie

Posts

Joined
Sat Apr 10, 2010 12:52 pm

Post by kedgetech » Tue Apr 27, 2010 7:20 pm

Tried partially works (opens in another iFrame sort of thing). I guess you should get some PHP developer to help you out.
Last edited by kedgetech on Sun Aug 22, 2010 10:39 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by Qphoria » Tue Apr 27, 2010 9:54 pm

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

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by bcit » Wed Apr 28, 2010 1:02 am

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.

Newbie

Posts

Joined
Sat Apr 10, 2010 12:52 pm

Post by Qphoria » Wed Apr 28, 2010 2:36 am

Works perfectly for me
Do you have a link to your site I can see?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by kedgetech » Wed Apr 28, 2010 5:50 am

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;
?>
}
Last edited by kedgetech on Sun Aug 22, 2010 10:39 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by bcit » Wed May 05, 2010 1:45 am

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.

Newbie

Posts

Joined
Sat Apr 10, 2010 12:52 pm

Post by Boekel » Thu Sep 23, 2010 8:20 pm

How do I change this using 1.4.8b?

Newbie

Posts

Joined
Mon Aug 30, 2010 9:38 pm

Post by dramony » Fri Sep 24, 2010 6:56 pm

is there a way to redirect the user to previous page(ex: product page) after login?

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm

Post by ahhcrap » 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!

Newbie

Posts

Joined
Fri Nov 12, 2010 11:18 am

Post by nightwing » 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!

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by straightlight » 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
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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nightwing » Wed Apr 15, 2020 10:17 pm

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.

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by straightlight » 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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nightwing » Thu Apr 16, 2020 1:13 am

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.

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm

Who is online

Users browsing this forum: Google [Bot] and 130 guests