Jump to content

Last items sold


dave
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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: [email protected]+
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'}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...

I do the same thing. enter your search, then push the refine key in the top right hand corner. then go to the bottom and turn on the completed listing button then push the search button in the top left corner and it will display the conpleted listing!  My Fortiva

Edited by Antonio021
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...