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