SpankyAndy Posted January 24, 2010 Share Posted January 24, 2010 Does anybody know if it is possible to have a link from product_info back to the items relavant category page if there are multiple results pages within the category? e.g. If an item is on page 3 of the category results, is it possible to dynamically link back to page 3 from product_info for that item? Going along the same lines, is it possible to do the above from shopping_cart after an item has been added? By default, the "Continue Shopping" button links back to the item that has just been purchased, which I've seen confusing customers many times when they're pressing their browser's back button. It would be much more of a fluid session for the customer if the "Continue Shopping" button linked back to the category page they were on before viewing the product. Cheers Andy Link to comment Share on other sites More sharing options...
germ Posted January 24, 2010 Share Posted January 24, 2010 Does anybody know if it is possible to have a link from product_info back to the items relavant category page if there are multiple results pages within the category? e.g. If an item is on page 3 of the category results, is it possible to dynamically link back to page 3 from product_info for that item? Going along the same lines, is it possible to do the above from shopping_cart after an item has been added? By default, the "Continue Shopping" button links back to the item that has just been purchased, which I've seen confusing customers many times when they're pressing their browser's back button. It would be much more of a fluid session for the customer if the "Continue Shopping" button linked back to the category page they were on before viewing the product. Cheers Andy Part of your answer can be found here If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
SpankyAndy Posted January 24, 2010 Author Share Posted January 24, 2010 Thanks Germ, that's helped, but I'm still stuck ... Using that technique, the back link works perfectly if navigating via the category pages to product_info, which is good. However, via different methods of navigation: Accessing a product directly via a search engine causes IE to hide the link completely. Whereas Firefox displays the link but href's the home page, which is a bit of a pain as I've inlcuded the category name within a more user friendly link text, rather than just using a generic back button/link. Jumping straight to product_info from a home page link causes IE and Firefox to link back to the home page, which again is no good if the category name is included within the link. The idea of this is to reduce page bounce when search engines return direct product links. I'm trying to draw visitors towards the categories, rather than allowing them to leave straight away. While the code you've highlighted takes me part way there for product_info, it still doesn't work for shopping_cart as the "Continue Shopping" button links back to product_info if the customer hits a product directly from a search engine, or the button disappears in both browsers if sizeof($navigation->path)-2; is changed to 3. Any ideas? Cheers Link to comment Share on other sites More sharing options...
germ Posted January 24, 2010 Share Posted January 24, 2010 You can't create a link back to a page you haven't visited in the first place. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
burt Posted January 24, 2010 Share Posted January 24, 2010 Yes, this is simple. Hints: tep_get_product_path() and tep_get_path() Very simple in the product page! A bit more complicated in the shopping cart page, but not so much as to be more than a bit of lateral thinking. "You can't create a link back to a page you haven't visited in the first place. " ???? Link to comment Share on other sites More sharing options...
germ Posted January 24, 2010 Share Posted January 24, 2010 Yes, this is simple. Hints: tep_get_product_path() and tep_get_path() Very simple in the product page! A bit more complicated in the shopping cart page, but not so much as to be more than a bit of lateral thinking. "You can't create a link back to a page you haven't visited in the first place. " ???? I never said constructing a link TO the page wasn't possible. You can't create a link back to a page you haven't visited in the first place. The "back" part just renders the navigation history useless. Maybe just an exercise in semantics but what I said was technically accurate. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
SpankyAndy Posted January 24, 2010 Author Share Posted January 24, 2010 Thanks for the help so far guys. I think tep_get_product_path is the function I've been looking for. Sorry to sound ignorant, but I don't know how to use it. I've tried to create a link using the following... tep_href_link(FILENAME_DEFAULT, tep_get_product_path($product_info['products_id'])) ... which looks correct to me, based on what I understand of the function in general.php. However, it returns the default home page. How do I return the category path using this function? Bearing in mind I'm looking for the relevant page within the category too. Leading on from this, is there a way to tell what the previous referring page was? The http referrer only shows an external site and remains static for the session. I want to be able to distinguish between somebody who has found a product via the category page and somebody who has accessed it directly from a search engine. Link to comment Share on other sites More sharing options...
burt Posted January 24, 2010 Share Posted January 24, 2010 Here is the way I did it on the product page; echo '<a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_path($current_category_id)) . '">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; For the shopping cart page, a little more problematic as you'll need to parse the contents of the cart array, grab the last added value (in other words the last added product) then use the get_product_path (rather than the get_path I used above) as current_category_id is always available at the product_info page, but not at the shopping cart page. I belive that you are on the right lines, however when using the _get_product_path as in your example, you would need to prepend it with cPath along the lines of echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . tep_get_product_path($product_info['products_id'])) . '">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; Link to comment Share on other sites More sharing options...
SpankyAndy Posted January 24, 2010 Author Share Posted January 24, 2010 I tried tep_get_path($current_category_id) earlier, but it returns the first page of the category. This is perfect for visitors who have accessed product_info directly from a search engine, but it will only frustrate customers who've just added a product to the cart after trawling through 14 pages of a category (for example) and want to carry on where they left off. Is there not an out of the box function that can return the path? I disabled breadcrumbs a long time ago, so I can't remember the behaviour, but didn't these take the user back to the correct page within the category? If no stock function exists, do you think it would be best to query the number of active products in the category, split them by the max products per page and then construct a path based on this? Link to comment Share on other sites More sharing options...
burt Posted January 24, 2010 Share Posted January 24, 2010 Oh god no, you can probably do something with tep_get_all_params, I actaully didn't pick up on that part of your original post lol Link to comment Share on other sites More sharing options...
SpankyAndy Posted January 24, 2010 Author Share Posted January 24, 2010 Haha, I thought you were making it sound too easy. I'll have a play with tep_get_all_params and see if there's anything I can use to create the path. I'll post back here when I've got something useful, as I'm sure I'm not the first person ever to want this feature. In the meantime, do you know if there's a way of getting the URL of the previous page? HTTP referrer only shows external referring URL's and remains static for the duration of the session. I want to be able to distinguish between somebody who has accessed product_info via a search engine and another who has accessed the product via the category pages. Knowing this will allow me to present them with a link to the beginning of the category (for direct search engine visitors who haven't seen other products within the category) or a link to the relevant result page within the category (for those who have navigated through the site and don't want to go back to the beginning of the category). Link to comment Share on other sites More sharing options...
burt Posted January 25, 2010 Share Posted January 25, 2010 Without thinking deeply - I rarely do lol - the simplest way may be to pass the page parameter thru the navigation class if the page parameter was used in the 1st place. Then if it exists you do one thing, and if it doesnt do another... Link to comment Share on other sites More sharing options...
SpankyAndy Posted January 31, 2010 Author Share Posted January 31, 2010 I've managed to crack this. I was thinking too much into it and overlooked the simple solution. Visitors who navigate via the category pages now have their last index.php path stored in the session. This is then used to create a back link in product_info and the continue shopping button in shopping_cart takes the user back to the category page they were last on, rather than back to the product or beginning of category. As this new session data is added/updated in index.php, users who do access a product directly from a search engine do not have the data. As a result, the lack of data causes product_info to create another value relating to the category of the current product. shopping_cart can use this data to fire a customer to the beginning of the product category when pressing the continue shopping button. This is a much smoother navigation for the visitors on my site and something I wish I'd had in from day 1. For those who are interested in doing the same, here's the changes I made: index.php After: require('includes/application_top.php'); Add: if(isset($_SESSION['external_visitor'])) { unset($_SESSION['external_visitor']); } if ($_SERVER["REQUEST_URI"] != "") { if (!tep_session_is_registered('back_page')) { tep_session_register('back_page'); } $_SESSION['back_page'] = $_SERVER["REQUEST_URI"]; } product_info.php After: require('includes/application_top.php'); Add: if ($_SERVER["REQUEST_URI"] != "") { if (!tep_session_is_registered('back_page')) { tep_session_register('external_visitor'); $_SESSION['external_visitor'] = tep_get_path($current_category_id); } } The following is the link back to the product's category which can be put anywhere on your page, but not required if you don't want to use it: <?php if ($_SESSION['back_page'] != '') { echo '<a href="' . $_SESSION['back_page'] . '" style="text-decoration:underline;">Back to <span style="font-weight:bold;font-size:14px;">' . tep_get_categories_name($cPath) . '</span> category</a></span>'; } else { echo '<a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_path($current_category_id)) . '" style="text-decoration:underline;">Back to <span style="font-weight:bold;font-size:14px;">' . tep_get_categories_name($cPath) . '</span> category</a></span>'; } ?> shopping_cart.php Replace: <?php $back = sizeof($navigation->path)-2; if (isset($navigation->path[$back])) { ?> <td class="main" align="left"><?php echo '<a href="' . tep_href_link($navigation->path[$back]['page'], tep_array_to_string($navigation->path[$back]['get'], array('action')), $navigation->path[$back]['mode']) . '">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; ?></td> <?php } ?> With: <?php if (tep_session_is_registered('back_page')) { $backpage = $_SESSION['back_page']; } else { $backpage = tep_href_link(FILENAME_DEFAULT, $_SESSION['external_visitor']); } ?> <td class="main" align="left"><?php echo '<a href="' . $backpage . '">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; ?></td> If anybody has any suggestions on how this may be done better, please feel free to comment. I'm a million miles away from being 'good' at PHP coding, but this works very well and does exactly what I need it to. Cheers Andy Link to comment Share on other sites More sharing options...
multimixer Posted February 6, 2010 Share Posted February 6, 2010 Hi, great ideas here I found following issue with the solution above: If somebody, after being in a category jumps directly to a product info page (ie because clicking the specials box) then the link goes back to the previously visited category and not the category the visitor is in. On the product info page we have if ($_SERVER["REQUEST_URI"] != "") { if (!tep_session_is_registered('back_page')) { tep_session_register('external_visitor'); $_SESSION['external_visitor'] = tep_get_path($current_category_id); } } Later on the link leads to the back page if this back_page exist This back_page is getting registered only on index.php, so the LAST VISITED index.php. That must not be the same as the actual category the product is in, when jumping directly to it. The statement on product info checks only if there is a back_page, not is this back_page match the actual category the product is in So, the issue is to make the if condition to check also if the category id of the back_page is same of the current category id My community profile | Template system for osCommerce - New: Responsive | Feedback channel Link to comment Share on other sites More sharing options...
multimixer Posted February 6, 2010 Share Posted February 6, 2010 I just see that I messed up a little in my previous post, I mixed 2 different issues. One more time, the problem: 1) For the product info page: If you arrive there from the net, or from any page that is not an index.php page, then everything works fine: You go back to the top of the category the product belong. If you arrive there being previously on the category (index.php) page, then also fine: You go back to page #14 of that category. The problem starts if you was on a category page earlier, but you arrive to the product info page without passing through its category page, lets say I was on category A, then visited specials.php from there a product that belongs to category B. The link will take me back to page #14 of category A 2) Same thing happens in the shopping cart, if I continue from (1) adding that product to the cart, then the continue shopping button will tae me to category A and not B This happens because after the back_page gets registered in any category listing page, it stays there till another category is visited. The product_info.php is looking just if if ($_SESSION['back_page'] != '') { Same happens in the shopping cart if (tep_session_is_registered('back_page')) { It should be checked if the category of this stored back_page is the same as the category the products belong to Now, I could not find a way to compare the $_SESSION['back_page'] with any $cPath or $current_category_id because it is stored in form of an url. Because I couldn't do that I did something else 1) In index.php I register one more session so it looks like this if(isset($_SESSION['external_visitor'])) { unset($_SESSION['external_visitor']); } if ($_SERVER["REQUEST_URI"] != "") { if (!tep_session_is_registered('back_page')) { tep_session_register('back_page'); tep_session_register('category_page'); //mm } $_SESSION['back_page'] = $_SERVER["REQUEST_URI"]; $_SESSION['category_page'] = tep_get_path($current_category_id);//mm } 2) In product_info.php I register the external visitor session always if ($_SERVER["REQUEST_URI"] != "") { //if (!tep_session_is_registered('back_page')) { // comment mm tep_session_register('external_visitor'); $_SESSION['external_visitor'] = tep_get_path($current_category_id); // } // comment mm } I add more conditions to the if condition, so it looks like this <?php if ( ($_SESSION['back_page'] != '') && $_SESSION['category_page'] == $_SESSION['external_visitor'] ) { // mm echo '<a href="' . $_SESSION['back_page'] . '" style="text-decoration:underline;">Back to <span style="font-weight:bold;font-size:14px;">' . tep_get_categories_name($cPath) . '</span> category</a></span>'; } else { echo '<a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_path($current_category_id)) . '" style="text-decoration:underline;">Back to <span style="font-weight:bold;font-size:14px;">' . tep_get_categories_name($cPath) . '</span> category</a></span>'; } ?> 3) In shopping_cart.php I do similar, so it looks like this if (tep_session_is_registered('back_page') && $_SESSION['category_page'] == $_SESSION['external_visitor'] ) { // mm $backpage = $_SESSION['back_page']; } else { $backpage = tep_href_link(FILENAME_DEFAULT, $_SESSION['external_visitor']); } So, ok that works, but it is for sure not the best that can be done.There must be a better way to compare the already existing $_SESSION['back_page'] with the current category id, not? My community profile | Template system for osCommerce - New: Responsive | Feedback channel Link to comment Share on other sites More sharing options...
SpankyAndy Posted February 11, 2010 Author Share Posted February 11, 2010 1) For the product info page: If you arrive there from the net, or from any page that is not an index.php page, then everything works fine: You go back to the top of the category the product belong. If you arrive there being previously on the category (index.php) page, then also fine: You go back to page #14 of that category. The problem starts if you was on a category page earlier, but you arrive to the product info page without passing through its category page, lets say I was on category A, then visited specials.php from there a product that belongs to category B. The link will take me back to page #14 of category A 2) Same thing happens in the shopping cart, if I continue from (1) adding that product to the cart, then the continue shopping button will tae me to category A and not B Hi, Fortunately, I don't have this navigation problem as my site doesn't use specials. However, there is one easy way I can see of correcting your problem... Add an "onclick" to your specials links which adds $_SERVER["REQUEST_URI"] to the back_page session data. This would take the user back to the page on which you clicked the specials product. Alternatively, you could also use an "onclick" within the link to get the products category and use this to build a path and store in the back_page session data, after which the user would be taken to the first page of the products category. Cheers Andy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.