Page 1 of 1
Continue button in cart back to last visited productpage
Posted: Sun Jul 31, 2011 5:15 pm
by dengine
In Opencart there's a continue shopping button in the cart page. If I was a customer I would assume that this button would bring me back to the past visited page with products. On default it redirects to the home page which can be very annoying if you last visited page 20 of a certain category. I made some adjustments so that it remembers the last visited page that has products on it.
Step 1
I added the following function to the Controller class in the core. (engine/controller.php)
protected function getcurrenturl() {
$url = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
return htmlentities(strip_tags($url));
}
Step 2
To store the visited page I use the session. If you want top remember the last visited category page go to catalog/controller/product/category.php and put the following code somewhere (I've put it all the way at the top inside the index function of that class.
$this->session->data['last_page'] = $this->getcurrenturl();
I've also put this in the manufacturer, search and special controllers. If you put it inside the product controller it will off course remember the last visited product. The value of the session gets overwritten whenever a customer visits one of these pages.
Step 3
Go to catalog/controller/checkout/cart.php and replace this:
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
with this:
if(isset($this->session->data['last_page'])){
$this->data['continue'] = $this->session->data['last_page'];
}else{
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
}
What it does, it checks if the session has a stored value. If not it redirects to the homepage.
I hope this helps in a better user experience.
Re: Continue button in cart back to last visited page
Posted: Sun Jul 31, 2011 5:32 pm
by SXGuy
or you could just edit the cart tpl file to use a javascript back function for the continue button.
Re: Continue button in cart back to last visited page
Posted: Sun Jul 31, 2011 7:08 pm
by dengine
Well that is possible but what if you came from a product detail page. With your solution you would be redirected to that same page which makes no sense. I guess it makes more sense to continue shopping on the last page with products. With my solution you could visit information pages etc. go to the cart again and click the continue button and continue where you last viewed products.
Re: Continue button in cart back to last visited productpag
Posted: Mon Aug 01, 2011 1:13 am
by webpie it.
Ok, this i omehing i have been thinking about and looking for. Only problem i see, ok so someone presses continue shopping, it takes them back to the last product viewed, naturally they are going to press back onnthe browser button, does this mean it takes them back to the shopping cart again, or does it take them back to page they viewed before the product thy are just on?
Hope this makes sense.
Chris
Re: Continue button in cart back to last visited productpag
Posted: Mon Aug 01, 2011 2:34 am
by dengine
Ok I'll try to explain more clearly. What it does is it stores the last page URL that has products on them. This can be products by manufacturer, specials, search page etc. Because I did not add the code to the productpage itself it doesn't store that url. So if a customer would be on page 5 with products by manufacturer, then goes to a product and add it to the cart, next he/she goes to the contactpage but decides he want to view the shoppingcart page. On the shoppingcart page he will see the continue shopping button. This button brings the customer back to page 5 of the products by manufacturer.
So it's up to you which page URL you want to store, just add this
$this->session->data['last_page'] = $this->getcurrenturl();
to every controller of a page you want to remember in the session. You say naturally they would press the back button in the browser but it would surprise you how much people dont even know this button exists and besides I want to be in control of the user experience within the shop.
I hope this helps. If you have more questions let me know.
Re: Continue button in cart back to last visited productpag
Posted: Tue Aug 02, 2011 5:03 pm
by heroes_46
Thanks guys...the conversation was very helpful!

Re: Continue button in cart back to last visited productpag
Posted: Wed Sep 21, 2011 11:44 pm
by spitos
Excellent work! Just what i was after, thank you.
I did find a couple of issues though with the first change:
Code: Select all
protected function getcurrenturl() {
$url = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
return htmlentities(strip_tags($url));
}
I found that upon hitting continue, I was redirected to the previous page BUT without the 'www. prefix so was losing my cart. To remedy this I changed the above line:
Code: Select all
$url = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
To
Code: Select all
$url = 'http://www.' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
But is there something to replace this dynamically instead?
Also found that after clicking continue in the cart coming from a search page, it was redirecting me to a URL that I wasn't previously on. It was putting the code for the ampersand '&' rather than just '&' in the URL.
So this:
Code: Select all
index.php?route=product/search&filter_name=searchtext
Was showing as:
Code: Select all
index.php?route=product/search&filter_name=searchtext
To remedy this I changed this line:
Code: Select all
return htmlentities(strip_tags($url));
to this:
All seems to work. Can anyone see any problem with those changes?
Re: Continue button in cart back to last visited productpag
Posted: Sat Nov 19, 2011 3:47 am
by jzmwebdevelopment
Step 3
Go to catalog/controller/checkout/cart.php and replace this:
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
with this:
if(isset($this->session->data['last_page'])){
$this->data['continue'] = $this->session->data['last_page'];
}else{
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
}
Could someone tell me what line this is in V 1.5.3?
Re: Continue button in cart back to last visited productpag
Posted: Sat Apr 07, 2012 7:24 pm
by tmotto21
Really interesting, this helped us out in a project so thanks for posting! :-)
Re: Continue button in cart back to last visited productpag
Posted: Mon Aug 13, 2012 5:26 pm
by mrjave
hi all,
does it work on V1.5.3.1?
kind regards,
Jave
Re: Continue button in cart back to last visited productpag
Posted: Sun Aug 26, 2012 10:09 am
by mrjave
hi,
This is a fantastic Mod.
please update this to V1.5.3.1.
many thanks.
Jave
Re: Continue button in cart back to last visited productpag
Posted: Tue Mar 26, 2013 6:26 pm
by saracadi
plsssssssssssssssss help me
If the user is not logged in, make the button contact button showing if not is login show button add cart opencart
pls i need this code thank you
Re: Continue button in cart back to last visited productpag
Posted: Tue Mar 26, 2013 6:28 pm
by saracadi
Re: Continue button in cart back to last visited productpag
Posted: Tue Oct 08, 2013 1:13 am
by blindjoedeath
Dengine - thanks for providing a good start to the code. I needed this functionality, so I got it working on my sites and created a free mod for others to use.
http://www.opencart.com/index.php?route ... 20shopping
Appreciate any feedback you guys have!
Re: Continue button in cart back to last visited productpag
Posted: Fri Jul 10, 2015 4:22 am
by theone
hello guys,
can anyone advice how can i implement this to opencart 2.0.3.1 ?
i mean Continue button in the cart should take back to the last visited product page.
thanks very much for your time.
best regards
Re: Continue button in cart back to last visited productpag
Posted: Fri Jul 10, 2015 4:40 pm
by OSWorX
theone wrote:hello guys,
can anyone advice how can i implement this to opencart 2.0.3.1 ?
i mean Continue button in the cart should take back to the last visited product page.
thanks very much for your time.
best regards
You can use this free mod here:
http://www.opencart.com/index.php?route ... n_id=22989
Re: Continue button in cart back to last visited productpag
Posted: Sat Jul 11, 2015 5:45 am
by theone
thanks a lot for your help, i tried the file but may some problem from my setup so it didnt worked then i applied to manually and now all good here.
best regards