Make the New Products for Month more useful

I’ve previously posted about this particular module, about replacing it with featured products, or special offers or whatever. Here is another idea that I came up with last night…

How about only showing products that were added to your store within the last 30 days? And having those 30 days “update” automatically? Well, it’s very simple, and takes only 1 small code change in the New Products Module.

So, open up /includes/modules/products_new.php and find this code:

[php]$new_products_query = tep_db_query(“select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from ” . TABLE_PRODUCTS . ” p left join ” . TABLE_SPECIALS . ” s on p.products_id = s.products_id, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd where p.products_status = ‘1’ and p.products_id = pd.products_id and pd.language_id = ‘” . (int)$languages_id . “‘ order by p.products_date_added desc limit ” . MAX_DISPLAY_NEW_PRODUCTS);[/php]

Change it to this:

[php]$new_products_query = tep_db_query(“select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from ” . TABLE_PRODUCTS . ” p left join ” . TABLE_SPECIALS . ” s on p.products_id = s.products_id, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd where p.products_status = ‘1’ and p.products_id = pd.products_id and pd.language_id = ‘” . (int)$languages_id . “‘ AND p.products_date_added > date_sub(NOW( ), INTERVAL 1 MONTH) order by p.products_date_added desc limit ” . MAX_DISPLAY_NEW_PRODUCTS);[/php]

Save the file and upload it to replace the older one (you might want to backup your older modile first). The pertinent pieve of code I added is:

[php]AND p.products_date_added > date_sub(NOW( ), INTERVAL 1 MONTH)[/php]

which takes the “products date added” date and compares it to the date 1 month ago. If the “product date added” date is NEWER than 1 month, the product will show in the module output.

Learn More

If you look at this MySQL page, you can learn more about the INTERVAL settings which can allow you to display your products appropriately. So if you add more products each day or week, use a “DAY” or “WEEK” INTERVAL…

Remember that running an online shop is all about making things as easy as possible for your potential buyers, and your previous customers.

Take It Further

How about having some links near the module output, which will allow a potential buyer to see what products you have added in the past hour (or day, or week, or month or whatever). Something like (obviously the links below are not real, they are example of what I am talking of):

Show products added in the last daythe last weekthe last month

When these are clicked the module refreshes to show your products as appropriate. How cool would that be?

3 Replies to “Make the New Products for Month more useful”

  1. FWIW: According to php.net/date_sub, this function may or may not be available in your particular install of PHP. It notes the following for version requirements: (No version information available, might be only in CVS)

    Also, at the bottom of the page, notes the following:

    Warning

    This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk.

    -jared

  2. Good job Gary. This give a sense to an unuseful module. The next step is to set the interval value in admin/configuration.
    Please use easier questions for spam protection. Really a dirty job to post 😉

Leave a Reply

Your email address will not be published. Required fields are marked *