5 replies [Last post]
seedseller's picture
Offline
Joined: 11/27/2007
Juice: 141
Was this information Helpful?

Is there a way to have a flag a product as a new product? I would like to have all new products listed with some sort of "NEW" icon for a period of time (say 7-14 days). I don't see anything like this in the docs.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Flag a Product as New

Easiest way is to just create a CCK field, a checkbox, that you can then add to your product template (use Contemplate) that, when the field is active, shows a "NEW" icon.

Unless you wanted to write a few lines of code within the template to check the current date, and if it's within a certain threshold, to show said icon. That wouldn't be too hard, I don't think.

EDIT: Off the top of my head, you could put something like this into a template. This will show a product as "New" for the first week after it's been published.

<?php
$created
= db_result(db_query("SELECT created FROM {uc_node} WHERE nid = %d", $node->nid));
$curTime = time();

if (

$curtime - $created <= 604800) print "NEW!";
?>

Not tested but I imagine it'd work, or work with some tweaking. Might be a cool feature to add, or expand upon in a Contribution. Variable time threshold for display, etc.

--
Help directly fund development: Donate via PayPal!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Flag a Product as New

You probably mean {node} instead of {uc_node}.

However, if you have access to $node->nid, you ought to be able to use $node->created as well.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Oh yeah, duh! Even

Oh yeah, duh! Sad Even better!

<?php

if(time() - $node->created < 604800) print "NEW!";
?>

--
Help directly fund development: Donate via PayPal!

seedseller's picture
Offline
Joined: 11/27/2007
Juice: 141
Re: Oh yeah, duh! Even

Thanks! Works well. It would be a nice addition to Ubercart for those of us that are less fluent PHP programmers.

sashomi's picture
Offline
Joined: 06/19/2008
Juice: 29
Flag Product as New

This functionality is interesting, but where exactly can I put this code

<?php
if(time() - $node->created < 604800) print "NEW!";
?>

I don't have .tpl.php file for the list view in catalog. I need to customize the TAPIr table to change the name of the product. The better will be to put theme_mark() or something like this, in order to have
<span class="marker">new</span>
for some period, let's say 1 month or week. Will anyone help me resolve this?