Zen Follower
- Join Date:
- Aug 2008
- Posts:
- 131
- Plugin Contributions:
- 0
Can I change the "back to shopping" behaviour?
Too bad no one seems interested in this thread :(
Started by adelante on 29 Apr 2007, 9:51 PM · Views: 8,627
Zen Follower
Too bad no one seems interested in this thread :(
Zen Follower
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.
Zen Follower
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?
Zen Follower
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...
Totally Zenned
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:
Live and learn... the Zen way.
New Zenner
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....
New Zenner
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.
New Zenner
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
Inactive
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:
<?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.
New Zenner
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?
New Zenner
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.
New Zenner
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>Zen Follower
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
New Zenner
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.
Zen Follower
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
New Zenner
Thanks to everyone on this thread. You just saved me hours of digging and experimenting and frustration.
Zen Follower
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?
Tell staff why this post should be reviewed.