I have a tested function to add a "new", "special" and/or "bestseller" icon in any desired location where products are displayed.
I will be submitting this to Free Addons when I finish documentation; I will post the basic code here for anyone who would like to test it before then.```php
<?php
// new/special/bestseller product icons function gjh42 20110104
//includes/languages/english/extra_definitions/your_template/product_icons_defines.php
define ('PRODUCT_ICONS_NEW', 'new');//define output content if desired
define ('PRODUCT_ICONS_SPECIAL', 'special');
define ('PRODUCT_ICONS_BESTSELL', 'bestsell');
define ('PRODUCT_ICONS_NEW_SHOW', true);//change to false to hide
define ('PRODUCT_ICONS_SPECIAL_SHOW', true);//change to false to hide
define ('PRODUCT_ICONS_BESTSELL_SHOW', true);//change to false to hide
define ('PRODUCT_ICONS_NEW_DAYS', '30');
define ('PRODUCT_ICONS_SPECIAL23', 'special id 23');
define ('PRODUCT_ICONS_BESTSELL_QTY', '10');
// /defines
//includes/functions/extra_functions/product_icons_functions.php
function product_icons($products_id) {
global $db;
$icons = '';
$iconssql = 'select products_date_added, products_ordered from ' . TABLE_PRODUCTS . ' where products_id = ' . (int)$products_id;
$icons_result = $db->Execute($iconssql);
//new icon
if (PRODUCT_ICONS_NEW_SHOW) {
$date_added = strtotime($icons_result->fields['products_date_added']);
$new_start = time() - ($days * 86400);
$icons .= ($date_added >= $new_start)? '<div class="productIcon new">' . PRODUCT_ICONS_NEW . '</div>': '';//won't work past 2038
}
//special icon
if (PRODUCT_ICONS_SPECIAL_SHOW) {
$specialsql = 'select specials_id from ' . TABLE_SPECIALS . ' where products_id = ' . (int)$products_id;
$special_result = $db->Execute($specialsql);
if (isset($special_result->fields['specials_id'])) {
$special = $special_result->fields['specials_id'];
$special_text = defined('PRODUCT_ICONS_SPECIAL' . $special)? constant('PRODUCT_ICONS_SPECIAL' . $special): PRODUCT_ICONS_SPECIAL;
$icons .= '<div class="productIcon special' . $special . '">' . $special_text . '</div>';
}
}
//bs icon
if (PRODUCT_ICONS_BESTSELL_SHOW) {
$bestsell = ($icons_result->fields['products_ordered']);
$icons .= ($bestsell >= PRODUCT_ICONS_BESTSELL_QTY)? '<div class="productIcon bestsell">' . PRODUCT_ICONS_BESTSELL . '</div>': '';
}
return $icons;
}
```
In /includes/modules/your_template/product_listing.php, around line 98, add
product_icons($listing->fields['products_id']) .
to get```php
case 'PRODUCT_LIST_NAME':
$lc_align = '';
$lc_text = product_icons($listing->fields['products_id']) . '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
break;
```
Add to your stylesheet```
.productIcon {
float: left;
background: #aabbee url(../images/your_image.gif) no-repeat;
width: 42px;
height: 23px;
margin: 0.5em;
}
.productIcon.new {
float: right;
background: #aabbee url(../images/new_icon.gif) no-repeat;
width: 32px;
height: 23px;
}
.productIcon.special23 {
float: left;
background: #aabbee url(../images/special23_icon.gif) no-repeat;
width: 50px;
height: 33px;
}
```Add or adjust styling to suit.