How can I add a recently viewed products navigation block to my template? Is there a built in Squirrelcart block for this?
How can I add a recently viewed products navigation block to my template? Is there a built in Squirrelcart block for this?
We do not have a feature for this. I wrote a custom one for you. It will be added to the next mid level release (v3.4.0). You can add this as follows to earlier versions:
1. Click Settings > Themes > Navigation Blocks in the control panel
2. Click Add New
3. Enter a name, like Recently Viewed
4. Enter the same value for the Header field
5. Enter this for the Content field:
6. Double check that there are no blank lines or spaces before the code you pasted in the Content field, and that there are no blank lines or spaces after the code. A blank space before or after will cause the nav block to appear even when no products have been viewed.PHP Code:<?php
$show_limit = 5;
if (is_array($SC['products_viewed'])) {
$prod_rns = array_unique(array_reverse($SC['products_viewed']));
$prod_rns_fixed = array();
foreach($prod_rns as $prod_rn) {
if ($show_limit-- == 0) break;
$prod_rns_fixed[] = array('record_number' => $prod_rn);
}
$prod_info = sc_products($prod_rns_fixed,'category_preview_box',1,5);
$Product_Rows = $prod_info['rows'];
if (!$Product_Rows) return false;
include sc_tpl('category_preview_main');
}
if ($_GET['action'] == 'show_detail' && is_numeric($_GET['rn'])) {
$SC['products_viewed'][] = $_GET['rn'];
}
?>
7. The value on the first line controls how many items will be shown:
If you want to show a different number, change that value.PHP Code:$show_limit = 5;
8. Click Save Changes
9. Add the nav block to your storefront:
http://www.squirrelcart.com/help/?Na...torefront.html
It will show the last viewed items, up to the value you enter in $show_limit.
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
Jaime,
That was extremely generous of you to provide the custom code for the module I needed. This is the first time I have actually had to use support for this product in the 4-5 years I have been using Squirrelcart and the response is a testament to how exceptional customer support can truly make a great product even better.
Thanks for a great product!
Scott
Hi Scott,
You're welcome! Glad to finally have this feature.![]()
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
I quickly implemented this as well. Nice feature, thanks.
Beery
Glad you like it!
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
Much appreciated! Very nice of you to do that!
Regards,
Tom
Jamie,
It is working, but I am getting an error code. Can you review the screen capture and let me know what permission I have not set up correctly.
Thanks!
P.S. - This is a very useful feature!
That's a warning only. It is indicating the theme config file can't be saved because permissions aren't set to allow it. That file is only used to port your theme to another installation. It won't effect the way anything works.
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
Love it....
Query - how can I change the code if i just want to output the link to the product without the picture? If there's existing code, can you please direct me there and i'll have a look into it?
thanks heaps.
The code above is showing products via the already existing template files used for the Category Preview navigation block which shows products in the same category of a product being viewed in detail. You can make this show whatever you want by changing it to use custom template files.
1. Create a new file recently_viewed_box.tpl.php in squirrelcart/themes/YOUR_CUSTOM_THEME/ with the following content:
2. Create a new file recently_viewed_main.tpl.php in squirrelcart/themes/YOUR_CUSTOM_THEME/ with the following content:PHP Code:<?php /* This line prevents direct access to template. Don't remove it. */ if (!defined('SC_INCLUDE_OK')) die; ?>
<!-- Template: <?php print basename(__FILE__) ?> -->
<li class="tip" title="<?php print $Tooltip ?>"><a href="<?php print $URL ?>"><?php print $Name?></a></li>3. Change the code that goes in the nav blocks Content field to:PHP Code:<?php /* This line prevents direct access to template. Don't remove it. */ if (!defined('SC_INCLUDE_OK')) die; ?>
<!-- Template: <?php print basename(__FILE__) ?> -->
<div class="recently_viewed nav_link_container">
<ul class="nav_links">
<?php foreach($Product_Rows as $Product_Row): $Product = $Product_Row['products'][0]; ?>
<?php print $Product['HTML'] ?>
<?php endforeach; ?>
</ul>
</div>
That code is identical to what I originally posted, with the template names changed to your custom templates.PHP Code:<?php
$show_limit = 5;
if (is_array($SC['products_viewed'])) {
$prod_rns = array_unique(array_reverse($SC['products_viewed']));
$prod_rns_fixed = array();
foreach($prod_rns as $prod_rn) {
if ($show_limit-- == 0) break;
$prod_rns_fixed[] = array('record_number' => $prod_rn);
}
$prod_info = sc_products($prod_rns_fixed,'recently_viewed_box',1,5);
$Product_Rows = $prod_info['rows'];
if (!$Product_Rows) return false;
include sc_tpl('recently_viewed_main');
}
if ($_GET['action'] == 'show_detail' && is_numeric($_GET['rn'])) {
$SC['products_viewed'][] = $_GET['rn'];
}
?>
That should show them in a list as links only, using the standard format we use for nav block links.
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
Much appreciated, works like a charm!
Thanks again
M
You're welcome.![]()
Thanks,
Jamie
PHP shopping cart software - Squirrelcart
Please rate or review us!![]()
Hotscripts ● PHP Resource Index
There are currently 1 users browsing this thread. (0 members and 1 guests)