dave Posted February 16, 2022 Share Posted February 16, 2022 Sorry I don't know if this is the right place but does anyone know how I can show a box like the "popular products" box but with the last few items sold on the site listed? I want to give an indication to others that people are buying from the site and as I sell unique items they go out of stock when one is bought, but I would like people to know what we had for future reference. Quote Link to comment Share on other sites More sharing options...
bsmither Posted February 17, 2022 Share Posted February 17, 2022 We can use a Code Snippet for this. In admin, Manage Hooks, Code Snippets tab, click Add Snippet. At the bottom of the list of existing snippets will be a form: Enabled: checked Unique ID: recentsold@CC600+ Execution Order: 99 Description: Populates a custom template with most recently sold items. Trigger: class.gui.display Version: 1.0 Author: https://forums.cubecart.com/topic/57577-last-items-sold/ PHP Code: <?php function __displayRecentlySoldProducts($count) { if (!$GLOBALS['smarty']->templateExists('templates/box.recent.php')) { return false; } if (($recentProductsSold = $GLOBALS['db']->select('CubeCart_order_inventory', array('DISTINCT'=>'product_id','product_code','name'), array('product_id' => ">0"), array('id' => "DESC"), $count, false, false)) !== false) { $vars = array(); $GLOBALS['language']->addStrings(array('catalogue' => array('title_recent' => "Recently Sold"))); // Need to manually assign the newly modified language array to Smarty's LANG variable $GLOBALS['language']->assignLang(); foreach ($recentProductsSold as $recent) { $recent['url'] = $GLOBALS['seo']->buildURL('prod', $recent['product_id'], '&', false); $vars[] = $recent; } $GLOBALS['smarty']->assign('RECENT', $vars); $content = $GLOBALS['smarty']->fetch('templates/box.popular.php'); $GLOBALS['smarty']->assign('RECENTLY_SOLD_PRODUCTS', $content); } } __displayRecentlySoldProducts(5); // Show 5 recently sold items. Save the snippet. Now, there needs to be a template file to show the products. We will basically copy the Best Sellers (Popular Products) template. In the Foundation skin template directory, create a new file with the name: box.recent.php Have as its contents: {* * CubeCart v6 * ======================================== * CubeCart is a registered trade mark of CubeCart Limited * Copyright CubeCart Limited 2017. All rights reserved. * UK Private Limited Company No. 5323904 * ======================================== * Web: http://www.cubecart.com * Email: [email protected] * License: GPL-3.0 https://www.gnu.org/licenses/quick-guide-gplv3.html *} {if $RECENT} <div class="panel" id="box-recent"> <h3>{$LANG.catalogue.title_recent}</h3> <ol> {foreach from=$RECENT item=product} <li><a href="{$product.url}" title="{$product.name}">{$product.name}</a></li> {/foreach} </ol> </div> {/if} Finally, there needs to be an edit that places this box on the main page. In the existing template: main.php Find: {include file='templates/box.featured.php'} {include file='templates/box.popular.php'} Add after (or before, or in-between) {include file='templates/box.recent.php'} Quote Link to comment Share on other sites More sharing options...
dave Posted February 17, 2022 Author Share Posted February 17, 2022 Thanks, that's the second thread you've given me code. I'm not ignoring you but have setup a dev site so I'm not working on the live site.Bit busy at the moment to do that and also need to rebuild my web server too. Really will try these thanks. Quote Link to comment Share on other sites More sharing options...
Antonio5656 Posted July 30, 2022 Share Posted July 30, 2022 (edited) I have exactly the same problem. Anyone got a suggestion? MyAtriumHealth App Edited August 1, 2022 by Antonio5656 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.