Zen Cart Logo
Forums / General Questions / How Display a NEW logo or icon in product listing for new products ?

How Display a NEW logo or icon in product listing for new products ?

Views: 4,277

Results 1 to 20 of 30
29 Dec 2010, 8:34 AM
#1
triumph avatar

triumph

New Zenner

Join Date:
Feb 2010
Posts:
36
Plugin Contributions:
0

How Display a NEW logo or icon in product listing for new products ?

Hi everybody,

Do you know a contrib which can display a NEW logo or icon in product listing and in product file for new products?

Thanks

:smile:

29 Dec 2010, 9:58 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How Display a NEW logo or icon in product listing for new products ?

****************************** DUPLICATE POSTING ******************************
Please follow the forum guidelines and only post an issue once
Add additional information that might assist in your original posting

http://www.zen-cart.com/forum/faq.php

Other Posting
http://www.zen-cart.com/forum/showthread.php?t=170982

29 Dec 2010, 2:56 PM
#3
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,288
Plugin Contributions:
39

Re: How Display a NEW logo or icon in product listing for new products ?

Here is a good tutorial http://www.zencarttips.com/?p=21

~Melanie

29 Dec 2010, 7:51 PM
#4
triumph avatar

triumph

New Zenner

Join Date:
Feb 2010
Posts:
36
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Thanks you :smile:

If someone know, to add New icon in the products listing... :smile:

29 Dec 2010, 10:20 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

The code in that tip is a bit sloppy and tailored for a database with "zen_" prefixes on tables; also, it will only work in the product info page.
I have tightened it up into a function that can be called from anywhere that products are displayed.```php

<?php // new product icon function gjh42 20101229 //$content .= new_icon($products_id, $days);//whatever variable/field holds product id; days to be "new" if other than 30 function new_icon($products_id, $days=30) { global $db; $datesql = 'select products_date_added from ' . TABLE_PRODUCTS . ' where products_id = ' . (int)$products_id; $date_result = $db->Execute($datesql); $date_added = strtotime($date_result->fields['products_date_added']); // (2003-11-03 12:32:17 -> seconds since 1/1/1970) $new_start = time() - ($days * 86400); $icon = ($date_added >= $new_start)? '<div class="newProduct"> </div>': ''; return $icon; } //EOF ``` To put it in the product listing next to the product name, find this in /includes/modules/your_template/product_listing.php around line 98```php case 'PRODUCT_LIST_NAME': $lc_align = ''; $lc_text = '<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; ``` and add new_icon($listing->fields['products_id'], 30) . to get```php case 'PRODUCT_LIST_NAME': $lc_align = ''; $lc_text = new_icon($listing->fields['products_id'], 30) . '<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``` .newProduct { float: left; background: url(../buttons/english/new.gif) no-repeat; width: 32px; height: 23px; margin: 0.5em; } ```and save your "New" image in /includes/templates/your_template/buttons/english/new.gif. Adjust the height and width to match the image.
30 Dec 2010, 8:06 AM
#6
triumph avatar

triumph

New Zenner

Join Date:
Feb 2010
Posts:
36
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Hi

Thanks you so much! :smile:

And to have only NEW logo, in products listing where i need to delete?

Thanks

30 Dec 2010, 9:42 AM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

Delete what? I don't understand the question.

30 Dec 2010, 10:35 AM
#8
triumph avatar

triumph

New Zenner

Join Date:
Feb 2010
Posts:
36
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

i just need NEW icon in products listing only, if it's possible to disable NEW icon in product file... :blush:

30 Dec 2010, 4:49 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

The code I posted would only put the "new" icon in the product listing. If you followed the tips site's directions to put one in the product info page, you need to reverse those steps to get rid of it.

31 Dec 2010, 6:19 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

DigitalShadow - I am looking at an extension to the function (to be called product_alert_icon($products_id) ) to cover specials and bestsellers. The bestsellers looks easy; the specials may take a bit more finagling to get useful results - don't know exactly what final steps will be needed yet. "Sale" applies to whole categories and would not really be relevant here.

4 Jan 2011, 5:36 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

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.
9 Feb 2011, 7:16 PM
#12
boggled avatar

boggled

Zen Follower

Join Date:
Mar 2006
Location:
Tennessee
Posts:
286
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Great code! I've been looking for something like this.

Question...

Where do I put the first php code? In a new file or an existing one?

31 Mar 2011, 11:50 PM
#13
pizza392 avatar

pizza392

New Zenner

Join Date:
Mar 2011
Posts:
76
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

thanks a lot
is it available in the downloads area?
which file do i put those codes?

1 Apr 2011, 4:33 AM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

It is not in Free Addons yet. I have an improved version of it about ready to submit, but you can easily make it work from what is here. Put the code in post 11, first box, in a new file
/includes/functions/extra_functions/product_icons_functions.php

Add to /includes/modules/your_template/product_listing.php as described in the second box in post 11.

Add the style rules in the third box to your stylesheet.

3 Apr 2011, 3:42 PM
#15
yan111 avatar

yan111

New Zenner

Join Date:
Feb 2011
Posts:
8
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Thank you for your work gjh42!

Bestsellers and specials worked like a charm, new products icon doesn't appear.

Maybe it's because I use older version of Zen Cart (1.3.8a).

I'm waiting for improved version in Free Addons, thanks once again!

4 Apr 2011, 3:30 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

That's odd... I must have pasted into post 11 a different (older) version of the code than what I had tested. As posted, the new icon won't work, because the code mixes the first and second versions of the "new" timespan determination. The $days in thisphp //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 } should be PRODUCT_ICONS_NEW_DAYS```php
//new icon
if (PRODUCT_ICONS_NEW_SHOW) {
$date_added = strtotime($icons_result->fields['products_date_added']);
$new_start = time() - (PRODUCT_ICONS_NEW_DAYS * 86400);
$icons .= ($date_added >= $new_start)? '<div class="productIcon new">' . PRODUCT_ICONS_NEW . '</div>': '';//won't work past 2038
}

The latest version works off of the admin "new products limited to" setting.
5 Apr 2011, 3:35 PM
#17
yan111 avatar

yan111

New Zenner

Join Date:
Feb 2011
Posts:
8
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Thanks, now it works perfectly!

6 Apr 2011, 4:11 PM
#18
boggled avatar

boggled

Zen Follower

Join Date:
Mar 2006
Location:
Tennessee
Posts:
286
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

It does work perfectly. Thank you! :)

When you submit the actual mod for this...will there be the option of changing the position of the icon?

I would love to be able to position it next to the image.

6 Apr 2011, 5:05 PM
#19
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How Display a NEW logo or icon in product listing for new products ?

I wasn't planning on that, but it would be a very simple edit, moving a snippet of code from one place to another.

product_icons($listing->fields['products_id']) . move to this sectionphp case 'PRODUCT_LIST_IMAGE': $lc_align = 'center'; if ($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) { $lc_text = ''; } else { if (isset($_GET['manufacturers_id'])) { $lc_text = '<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']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>'; } else { $lc_text = '<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']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>'; } } break; in two places:```php
$lc_text = product_icons($listing->fields['products_id']) .'<a href="' . zen_href_link(...


I will at least give the instructions for this option, if I don't find a convenient way to make it selectable.
7 Apr 2011, 4:04 PM
#20
boggled avatar

boggled

Zen Follower

Join Date:
Mar 2006
Location:
Tennessee
Posts:
286
Plugin Contributions:
0

Re: How Display a NEW logo or icon in product listing for new products ?

Wow - that worked great! Thank you so much. :)