-
Can I change the "back to shopping" behaviour?
I'd like to change the "back to shopping behaviour" on a Zen cart that I'm working on. Currently when you click the back to shopping icon in the checkout you're taken back to the last product you ordered. I would like to go back to the product listing instead. Is this possible?
I demonstrated the flow to a friend and he pointed out that it didn't make a lot of sense to go back to what you have already ordered, he's got a good point.
Any help greatly appreciated.
-
Re: Can you change the "back to shopping" behaviour?
It appears that this is configurable, I have visited another zen cart store and you return to the home page when you click on the back to shopping icon. I've been pouring through the admin menus but don't seem to find the control. Any suggestions?
Many thanks
-
Re: Can you change the "back to shopping" behaviour?
Two ways:
1. You'll have to edit the button in the template to point back to a product-listing of sorts. This would end up with a hard-coded link back to whichever product-listing screen you code it for.
or
2. Either that or you'll need to carefully study the navigation class and its implementation in order to work out the various code changes that will be required to make it work dynamically.
-
Re: Can you change the "back to shopping" behaviour?
Hi Dr Byte,
Thanks for the clue, I've done a bit of programming but not much in PHP so this will be a nice exercise for me. Could you let me know if I'm on the right track with the logic.
I have looked at the tpl_shopping_cart_.default.php file and have found the variable for the back to shopping link is zen_back_link. What I'm thinking of doing is replacing it with a new path variable called last_category so the line would be:
<div class="buttonRow back"><?php echo last_category() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?>
What I would like to do is assign this variable when you enter a category listing page so when you order an item and get taken to the checkout the last category you visited would be in the variable.
I note the address for the category listing pages are in this format:
http://domain.com.au/index.php?main_page=index&cPath=4
where the end number is the category number of the products being shown. I imagine that if I find a variable that contains the category number I should be able to construct the url. Is there such a variable? It would need to be in both the category list and the product detail page.
Once I have it I'll be able to write some code to construct the url then assign it to my last_category variable. So when you click on the back to shopping icon it should go back to the category page.
Am I on the right track and can anyone help with the identity of the variables I'm looking for?
Thanks for your help
-
Re: Can you change the "back to shopping" behaviour?
Here's the quick and dirty solution that I've come up with. It involves setting up a template override for the following files:
includes/templates/template_default/templates/tpl_index_product_list.php and
includes/templates/template_default/templates/tpl_shopping_cart_default.php
in the tpl_index_product_list.php insert the following lines of code at line 15 (just above "<div class="centerColumn" id="indexProductList">"
<!-- start record category being visited adelante /-->
<!-- reset the session variable /-->
<?php unset($_SESSION["last_category_visited"]);
<!--set the variable last category visited wit the current product category number /-->
session_start();
$_SESSION["last_category_visited"] = $current_category_id;
?>
<!-- end record category being visited adelante /-->
in the tpl_shopping_cart_default.php insert the following lines of code at line 130 which is just above "<!--bof shopping cart buttons-->"
<!-- Generate back to shopping path 04052007 Adelante /-->
<?php
$back_shopping_path = '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . 'index.php?mainpage=index&cPath=' . $_SESSION["last_category_visited"] .'">' ;
?>
<!--end back to shopping path /-->
You will also need to change the line
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
to
<div class="buttonRow back"><?php echo $back_shopping_path . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
How it works:
A session is set up to record the product category number for the page that is being visited. This is found in the variable $current_category_id and is set to the session variable last_category_visited.
When you go to the checkout the session variable is read and used in the construction of the url for the category page that was last visited.
If you login and visit the checkout directly clicking on the back to shopping icon takes you to the home page.
It would be nice to capture the split page data as well but I haven't found the variables as yet.
I'd appreciate any inputs or comments that make make this solution more elegant. I hope it is useful to some.
Many thanks
-
Re: Can you change the "back to shopping" behaviour?
Is it possible to change that behavior to a specific url?
-
Re: Can you change the "back to shopping" behaviour?
You can customize your template for the shopping_cart to go anywhere you like for the Continue Shopping button ...
-
Re: Can you change the "back to shopping" behaviour?
You can hard code the button or set the path in the variable $back_shopping_path
-
Re: Can you change the "back to shopping" behaviour?
thanks for this! just what i needed. and thanks for the thorough explanation too!!
-
Re: Can you change the "back to shopping" behaviour?
i dont have time right now to do this, but a switch to turn this on or off in admin would be great wouldnt it. you could choose the default behavior of the continue shopping button in the mystore config. go to item or go to category or always go home. something like that and then base the logic around the swich... hmm
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
Minnie Mouse
i dont have time right now to do this, but a switch to turn this on or off in admin would be great wouldnt it. you could choose the default behavior of the continue shopping button in the mystore config. go to item or go to category or always go home. something like that and then base the logic around the swich... hmm
There is a switch ... Admin->Configuration->My Store->Display Cart After Adding Product ... goto shopping cart or not.
-
Re: Can you change the "back to shopping" behaviour?
no that's the reverse of what is needed. we want a switch that governs the behavior of the continue shopping button, not one that governs the add to cart button.
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
Minnie Mouse
no that's the reverse of what is needed. we want a switch that governs the behavior of the continue shopping button, not one that governs the add to cart button.
oops ... i read that too quickly.
-
Re: Can you change the "back to shopping" behaviour?
yes, but it is a good thought for building it. it is probably similar to what is needed and could be adapted to this.
L
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
adelante
Here's the quick and dirty solution that I've come up with. It involves setting up a template override for the following files:
includes/templates/template_default/templates/tpl_index_product_list.php and
includes/templates/template_default/templates/tpl_shopping_cart_default.php
in the tpl_index_product_list.php insert the following lines of code at line 15 (just above "<div class="centerColumn" id="indexProductList">"
<!-- start record category being visited adelante /-->
<!-- reset the session variable /-->
<?php unset($_SESSION["last_category_visited"]);
<!--set the variable last category visited wit the current product category number /-->
session_start();
$_SESSION["last_category_visited"] = $current_category_id;
?>
<!-- end record category being visited adelante /-->
in the tpl_shopping_cart_default.php insert the following lines of code at line 130 which is just above "<!--bof shopping cart buttons-->"
<!-- Generate back to shopping path 04052007 Adelante /-->
<?php
$back_shopping_path = '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . 'index.php?mainpage=index&cPath=' . $_SESSION["last_category_visited"] .'">' ;
?>
<!--end back to shopping path /-->
You will also need to change the line
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
to
<div class="buttonRow back"><?php echo $back_shopping_path . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
This seems like the only viable solution-- to prevent the cart from simply throwing users back to my home page (which I myself find pretty annoying). Generally, our users purchase several items, often in the same category. Throwing the user away from the listing could cost us sales, or perhaps even cause us to lose customers.
-
Re: Can you change the "back to shopping" behaviour?
It worked flawlessly. Now if I can just get it to work with Chemo's Ultimate URLs... & send the user to an optimized URL...
I've been fighting with Chemos Ultimate URL mod because he uses -c- in categories and -p- in products, along with the category & product numbers where applicable--
I really want perfectly clean URLs like wordpress uses--
If only I understood their php redirect system, I could alter Chemos URL mod on my own...
-
Re: Can you change the "back to shopping" behaviour?
Here's a link to the forum support for Chemo's mod...
http://www.zen-cart.com/forum/showth...35034&page=143
-
Re: Can you change the "back to shopping" behaviour?
I've ended up uninstalling chemo's mod, it's too buggy & no one seems to be supporting it right now.
-
Re: Can you change the "back to shopping" behaviour?
I'm adding an item from this link:
/index.php?main_page=index&cPath=65_68_70_77
then, when I choose back to shopping, it's sending me to:
/index.php?main_page=index&cPath=77
this is with the modification from Adelante.. is there any other possible way to do this, so that it correctly includes all the categories? "/index.php?main_page=index&cPath=77" sends me to a strange looking page.... (it doesn't show the subcatogories open on the left sidebar).
-
Re: Can you change the "back to shopping" behaviour?
Ok, I'm posting again because I love talking to myself..
no seriously though--
I noticed on my product pages the "listing" button (in between my prev/ next buttons on my cart) does exactly what I wish my "return to shopping" button will do.
Is there some way I can safely use something similar on the backend of my "return to shopping button"?
-
Re: Can you change the "back to shopping" behaviour?
Too bad no one seems interested in this thread :(
-
Re: Can you change the "back to shopping" behaviour?
Ok--here's a solution that works for me...
the other 'fix' here, wasn't a fix at all, I've got a complex site with many category levels.... etc.
Ok, here's the code I started with in the file: tpl_shopping_cart_default.php
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
Now, here's what I changed it to:
<div class="buttonRow back"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, "cPath=$cPath"); ?>"><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT); ?></a></div>
Works perfectly for me, gets right back to the category of the last product I added to the cart.
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
dontknowwhatimdoing
Ok--here's a real solution...
the other 'fix' here, wasn't a fix at all, I've got a complex site with many category levels.... etc.
Ok, here's the code you start with in the file: tpl_shopping_cart_default.php
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
Now, here's what you change it to:
<div class="buttonRow back"><a href="<?php echo zen_href_link(FILENAME_DEFAULT, "cPath=$cPath"); ?>"><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT); ?></a></div>
Works perfectly for me, gets right back to the proper listing.
Turns out this is a halfway solution. It only works if someone uses the "add to cart button". If they view the product listing first, it does not work.
Here's a good question I think: how can I make sure the $cpath variable gets loaded if someone is adding to cart from a product listing?
-
Re: Can you change the "back to shopping" behaviour?
Blah, blah, blah...ignore everything else I wrote (unless you have a proper PHP solution, then cough it up!)
Ok--the only solution I can come up with, is just a simple javascript back. If the user has javascript disabled, then oh well.
Nothing else works 100% or even 60% properly for me.
You can see the old version of the button link above, here's the new version:
<div class="buttonRow back"><a onclick="javascript:history.go(-1)"><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT); ?></a></div>
Notice.. I didn't include <a href="...
The reason is, I think it looks a bit sloppy, so I just buried the function inside an onclick function.
If I clean up my store URLs, I might do this to a lot of buttons if I'm too lazy to fix internal links...
Sneaky, sneaky, sneaky...
-
Re: Can you change the "back to shopping" behaviour?
Just want to say thank you! I never had time to do it earlier but I have this installed on all carts I maintain. This is a must! What good is it if you put something in your cart and after you want to go back shopping and you get bounced to the home page? Most likely I would like to continue where I left off shopping. Right?
Its like at the brick and mortar store they would send you back to the door every time you put something in the shopping basket!
Feature should be standard behavior. :clap:
-
Re: Can you change the "back to shopping" behaviour?
I haven't tested it completely, and I've got way too much extra code to verify it works on a "normal" site, but it looks like the problem is in
"includes/functions/functions_general.php"
around lines 992 and 1010, there is
if (sizeof($_SESSION['navigation']->path)-2 > 0) {
I changed this to be
if (sizeof($_SESSION['navigation']->path)> 1) {
and then the continue shopping button took me back to the page I was looking at when I added the product to the cart....
Your results may vary.. but it's something to try....
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
vrtisworks
I haven't tested it completely, and I've got way too much extra code to verify it works on a "normal" site, but it looks like the problem is in
"includes/functions/functions_general.php"
around lines 992 and 1010, there is
if (sizeof($_SESSION['navigation']->path)-2 > 0) {
I changed this to be
if (sizeof($_SESSION['navigation']->path)> 1) {
and then the continue shopping button took me back to the page I was looking at when I added the product to the cart....
Your results may vary.. but it's something to try....
thank you! :clap:
Its working perfectly for me so far.
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
dontknowwhatimdoing
You can see the old version of the button link above, here's the new version:
<div class="buttonRow back"><a onclick="javascript:history.go(-1)"><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT); ?></a></div>
Man, this is sooo cool! I've been trying to figure out how to do this for hours! Thank you!
Druber
-
Re: Can you change the "back to shopping" behaviour?
I just wanted to say that when I added Adelante's code to the site I'm working on, it broke my product listing index pages.
In case it happens to anyone else, it's because of the comments. Session data truly must be the FIRST thing that shows up on a page. Stuff that is commented out is okay, BUT he's using HTML comments, not PHP. Therefore HTML is showing up before the session data - and breaking the pages.
To fix it, just replace his original code with this:
Code:
<?php // reset the session variable
unset($_SESSION["last_category_visited"]);
// change the variable from "last category visited" to "current product category number"
session_start();
$_SESSION["last_category_visited"] = $current_category_id;
?>
note how now the comments are within the PHP tags - so the session data is *still* first in line. It works like a charm now.
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
vrtisworks
I haven't tested it completely, and I've got way too much extra code to verify it works on a "normal" site, but it looks like the problem is in
"includes/functions/functions_general.php"
around lines 992 and 1010, there is
if (sizeof($_SESSION['navigation']->path)-2 > 0) {
I changed this to be
if (sizeof($_SESSION['navigation']->path)> 1) {
and then the continue shopping button took me back to the page I was looking at when I added the product to the cart....
Your results may vary.. but it's something to try....
Is there a way to have the button take you to a specific URL instead of just going back?
-
Re: Can you change the "back to shopping" behaviour?
Technically.... Yes. If you look at the statements following the IF statements, they set $link=<a ... then, the back button can be made to go anywhere.
I suspect that it would be confusing to the user if the Back button did not take them back to where they were, but off to some other page though.
-
Re: Can you change the "back to shopping" behaviour?
Quote:
Originally Posted by
harrylshulman
Is there a way to have the button take you to a specific URL instead of just going back?
Yea this is what I changed the line to, as I wanted to go back to the home page, but just change the url to what ever you desire.
Original Code and File: /includes/templates/template_default/templates tpl_shopping_cart_default.php
<div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
Changed to -
<div class="buttonRow back"><?php echo '<a href="index.php">' . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPING, BUTTON_CONTINUE_SHOPPING_ALT) . '</a>'; ?></div>
-
Re: Can I change the "back to shopping" behaviour?
Thanks to adelante... I tried a few fixes for this and his suited my needs best.
I would have never figured that out myself.
Only thing is that it is not working if I viewed, then added to cart from a dynamically generated category. I.E. All Products.
If I have previously added a product from a defined category it returns there instead.
I suspect it has to do with the fact that the categories are dynamically generated, or perhaps it's something to do with my URI re-write module.
If anyone has figured out how to get this to work, I would greatly appriciate some advise.
David
countrytothecore.net
-
Re: Can I change the "back to shopping" behaviour?
I'm glad the little mod has been useful. australican I think it's because you're you actually in a category, personally I don't use the show all products menu item. I'll have to re-vist the code and have a look again.
-
Re: Can I change the "back to shopping" behaviour?
My little e-shop is an extension of our little B&M gift shop and fairly new. I'm still just testing really. I've never been an online shopper so I don't know how many shoppers would use All or New categories yet, but would still like to clean up that loose end.
Personally All seems silly, especially for shops with large amounts of products. It's probably intended for shop with only a dozen or so items.
I like to give people as many options as possible, but too many might just lead to confusion.
Anyone else have an opinion or words of wisdom on this?
(Not that yours wasn't relevant adelante)
Anywho... Thanks again for the little mod.
David
-
Re: Can you change the "back to shopping" behaviour?
Thanks to everyone on this thread. You just saved me hours of digging and experimenting and frustration.
-
Re: Can I change the "back to shopping" behaviour?
brilliant exactly what I wanted to do, have the button just go 'back' :-) thanks!
But...only problem is, the buttons there (ive made my own) it goes back when you click on it but on the hover over it doesnt change, looks like an inactive button that doesnt link to anything only when you click it does it actually work. Any ideas?