Post by dengine » Sun Jul 31, 2011 5:15 pm

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.
Last edited by dengine on Sun Jul 31, 2011 7:11 pm, edited 2 times in total.

OpenCart Developer sinds versie 1.4.9.3. Inmiddels volledige CMS geïntegreerd binnen OC 1.5. Sta open voor uitdagende custom uitbreidingen en custom themes, inclusief responsive design.

GEMAAKT MET OPENCART
http://www.worldofbessy.com
http://www.kiddycolors.com
http://www.ke-works.com
http://www.trendyard.nl
http://www.bigliftshipping.nl
http://www.kosterklokken.nl


New member

Posts

Joined
Sun Mar 06, 2011 6:52 pm
Location - Colijnsplaat / Den Haag

Post by SXGuy » Sun Jul 31, 2011 5:32 pm

or you could just edit the cart tpl file to use a javascript back function for the continue button.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by dengine » Sun Jul 31, 2011 7:08 pm

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.

OpenCart Developer sinds versie 1.4.9.3. Inmiddels volledige CMS geïntegreerd binnen OC 1.5. Sta open voor uitdagende custom uitbreidingen en custom themes, inclusief responsive design.

GEMAAKT MET OPENCART
http://www.worldofbessy.com
http://www.kiddycolors.com
http://www.ke-works.com
http://www.trendyard.nl
http://www.bigliftshipping.nl
http://www.kosterklokken.nl


New member

Posts

Joined
Sun Mar 06, 2011 6:52 pm
Location - Colijnsplaat / Den Haag

Post by webpie it. » Mon Aug 01, 2011 1:13 am

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

Regards

Chris


Active Member

Posts

Joined
Mon Jan 31, 2011 7:28 pm

Post by dengine » Mon Aug 01, 2011 2:34 am

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.

OpenCart Developer sinds versie 1.4.9.3. Inmiddels volledige CMS geïntegreerd binnen OC 1.5. Sta open voor uitdagende custom uitbreidingen en custom themes, inclusief responsive design.

GEMAAKT MET OPENCART
http://www.worldofbessy.com
http://www.kiddycolors.com
http://www.ke-works.com
http://www.trendyard.nl
http://www.bigliftshipping.nl
http://www.kosterklokken.nl


New member

Posts

Joined
Sun Mar 06, 2011 6:52 pm
Location - Colijnsplaat / Den Haag

Post by heroes_46 » Tue Aug 02, 2011 5:03 pm

Thanks guys...the conversation was very helpful! :)

Business Cards and other Printing Services provided by CardsMadeEasy!
Contact Us for more information on business card printing!


Newbie

Posts

Joined
Tue Aug 02, 2011 4:56 pm

Post by spitos » Wed Sep 21, 2011 11:44 pm

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:

Code: Select all

return ($url);
All seems to work. Can anyone see any problem with those changes?

Image
Google Analytics Expert - Advanced e-commerce tracking, Product & options reporting, transaction/conversion reporting, Google Adwords conversion & profit reporting, goal & funnel reporting, event tracking, site search tracking, multi-store compatibility, EU Cookie Law compliance and works with any theme or checkout! Easy vqmod install. Get it here


User avatar
Active Member

Posts

Joined
Mon May 23, 2011 6:19 pm
Location - UK

Post by jzmwebdevelopment » Sat Nov 19, 2011 3:47 am

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?

New member

Posts

Joined
Fri Feb 25, 2011 9:54 am

Post by tmotto21 » Sat Apr 07, 2012 7:24 pm

Really interesting, this helped us out in a project so thanks for posting! :-)

Todd Motto http://www.toddmotto.com | Brand Identity/Graphic Designer & Front-End Web Developer


Newbie

Posts

Joined
Sat Apr 07, 2012 7:22 pm

Post by mrjave » Mon Aug 13, 2012 5:26 pm

hi all,

does it work on V1.5.3.1?

kind regards,
Jave

Active Member

Posts

Joined
Wed Jun 13, 2012 4:22 pm

Post by mrjave » Sun Aug 26, 2012 10:09 am

hi,

This is a fantastic Mod.
please update this to V1.5.3.1.

many thanks.

Jave

Active Member

Posts

Joined
Wed Jun 13, 2012 4:22 pm

Post by saracadi » Tue Mar 26, 2013 6:26 pm

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

Newbie

Posts

Joined
Tue Mar 26, 2013 5:55 pm

Post by saracadi » Tue Mar 26, 2013 6:28 pm

:'( :'( :'( :'( :'( 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

Newbie

Posts

Joined
Tue Mar 26, 2013 5:55 pm

Post by blindjoedeath » Tue Oct 08, 2013 1:13 am

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!

My Opencart Extensions
My site for installed home products: Home - Windows - Water Heaters -
Furnaces - and more!


Newbie

Posts

Joined
Fri Jul 19, 2013 2:17 am

Post by theone » Fri Jul 10, 2015 4:22 am

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

New member

Posts

Joined
Sat Oct 30, 2010 9:09 am

Post by OSWorX » Fri Jul 10, 2015 4:40 pm

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

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by theone » Sat Jul 11, 2015 5:45 am

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

New member

Posts

Joined
Sat Oct 30, 2010 9:09 am
Who is online

Users browsing this forum: No registered users and 2 guests