Thread: Newest Products
View Single Post
  #138  
Old 04-09-2006, 04:49 AM
  cliffo4's Avatar 
cliffo4 cliffo4 is offline
 

Member
  
Join Date: Jul 2005
Location: Leicester, UK
Posts: 19
 

Default

Quote:
Originally Posted by MallRomania
All i want is to display newest products in main page, not only when press link. Something similar with featured products will be be very good. Can you send me your code please? (admin@mallromania.ro)

Thank you

Well in the spirit of sharing here is the basis of thing. Do take into account that I have taken out some of the more specific requirements of my development to give a basis to be working on. Code based on Xcart Gold 4.0.18

/modules/Bestsellers/bestsellers.php.

Code:
<?php /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2005 Ruslan R. Fazliev <rrf@rrf.ru> | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2005 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: bestsellers.php,v 1.24.2.4 2006/01/16 14:58:31 mclap Exp $ # # Bestsellers and now newitems at same time to save some processing # if (!defined('XCART_SESSION_START')) { header("Location: ../../"); die("Access denied"); } if ($active_modules['Bestsellers'] || $active_modules['Newitems']){ if (!is_numeric($config["Modules"]["number_of_bestsellers"])) $config["Modules"]["number_of_bestsellers"] = 0; # # Get products data for current category and store it into $products array # $avail_condition = ""; if ($config["General"]["unlimited_products"] == "N" && $config["General"]["disable_outofstock_products"] == "Y") $avail_condition = " AND $sql_tbl[products].avail>0 "; $cat = intval($cat); if ($cat) { $category_data = func_query_first("SELECT categoryid_path, threshold_bestsellers FROM $sql_tbl[categories] USE INDEX (PRIMARY) WHERE categoryid='$cat'"); $result = func_query("SELECT categoryid, threshold_bestsellers FROM $sql_tbl[categories] USE INDEX (pam) WHERE categoryid_path LIKE '$category_data[categoryid_path]/%' AND avail='Y'"); $threshold = (int)$category_data["threshold_bestsellers"]; $cat_ids = array(); if (is_array($result)) { foreach($result as $k=>$v) { $cat_ids[] = $v["categoryid"]; if ($v["threshold_bestsellers"]>0 && $threshold > $v["threshold_bestsellers"]) $threshold = $v["threshold_bestsellers"]; } } else $cat_ids[] = $cat; $str = " AND $sql_tbl[products_categories].categoryid IN (".implode(",", $cat_ids).")"; if ($threshold) $threshold -=1; $search_query1 = $str." AND $sql_tbl[products].views_stats>0 AND $sql_tbl[products].sales_stats > $threshold"; } else { $threshold = 0; $search_query1 = " AND $sql_tbl[products].sales_stats>$threshold"; } $search_query2 = " AND $sql_tbl[products].add_date>UNIX_TIMESTAMP()-(14*86400) and $sql_tbl[products].add_date >0 and $sql_tbl[products].forsale='Y'"; $order_by1 = "$sql_tbl[products].sales_stats DESC, $sql_tbl[products].views_stats DESC"; $order_by2 = "rand()"; #$order_by2 = "$sql_tbl[products].views_stats, $sql_tbl[products].newdate_until desc"; \\least viewed by youngest item # # Search the bestsellers and newitems # if ($active_modules['Bestsellers']) { $bestsellers = func_search_products($search_query1, @$user_account["membership"], $order_by1, $config["Modules"]["number_of_bestsellers"]); $smarty->assign("bestsellers",$bestsellers); } if ($active_modules['Newitems']) { $tmp_str = $str.$search_query2; $bestsellers = func_search_products($str.$search_query2, @$user_account["membership"], $order_by2, $config["Modules"]["number_of_bestsellers"]); if (empty($bestsellers) and $cat) $bestsellers = func_search_products($search_query2, @$user_account["membership"], $order_by2, $config["Modules"]["number_of_bestsellers"]); $smarty->assign("newitems",$bestsellers); } } ?>

You may want to pay attention to the query2 string above in relation to column "add_date" as my system uses a different column due to other mods I have made on cart.

skin1/modules/Newitems/newitems.tpl
Code:
{* $Id: newitems.tpl,v 1.3.2.1 2006/03/12 11:15:01 max Exp $ *} {if $newitems and $active_modules.Newitems} {capture name=newitem} <TABLE cellpadding="2" cellspacing="2" border="0"><tr valign="top"> {section name=num loop=$newitems max=5} <TD align="center" width="20%"> <A href="product.php?productid={$newitems[num].productid}">{if $config.Modules.bestsellers_thumbnails eq "Y"} {include file="product_thumbnail.tpl" productid=$newitems[num].productid image_x=90 product=$newitems[num].product} {/if} {$newitems[num].product} <FONT class="ProductPrice">{$lng.lbl_price}:</FONT> {if $newitems[num].price eq 0 and $product.avail lt 1}<FONT class="ProductDetailsTitle"><SPAN id="product_price">{$lng.lbl_TBC}</SPAN></FONT>{else} {if $newitems[num].price ne 0 || $variants ne ''} <FONT class="ProductDetailsTitle"><SPAN id="product_price">{include file="currency.tpl" value=$newitems[num].price}</SPAN></FONT><FONT class="MarketPrice"> <SPAN id="product_alt_price">{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$newitems[num].price}</SPAN></FONT> {if $newitems[num].taxes} {include file="customer/main/taxed_price.tpl" taxes=$newitems[num].taxes}{/if} {else}{$lng.lbl_enter_your_price}{/if}{/if}</A> {/section}</tr><tr><td align="center" colspan="{$smarty.section.num.total}">more new items</td></tr></TABLE> {/capture} {include file="dialog.tpl" title=$lng.lbl_newproducts content=$smarty.capture.newitem extra="width=100%"} {/if}
This template may need some alteration as I test for Zero price and do some other bits - feel free to alter to fit your needs.

Edit skin1/customer/home.tpl
Code:
{include file="location.tpl"} {include file="dialog_message.tpl"} {if $active_modules.Special_Offers ne ""} {include file="modules/Special_Offers/customer/new_offers_message.tpl"} {/if} {include file="customer/home_main.tpl"} {include file="modules/NewItems/newitems.tpl"}

Upto you how and where you place the block - it should come out as a horizontol block with 5 items listed. It can be added elsewhere and will be category sensitive (like bestsellers is). Meaning it will show newest 5 items in currently selected category or if there are none, will do a global search.

Add some sql to xcart:
Code:
INSERT INTO `xcart_modules` VALUES (64, 'Newitems', 'Show Newest items added to site', 'Y');
This will result in you seeing in admin/modules a new module - obviously do activate it to enable the block on front page.

Think thats about it. Can't promise it will work as it is as I've had to pull it all out from my mods - Good luck - and the fun is when you do get it to happen
__________________
X-Cart Gold 4.0.19
http://interstellarsounds.com
Reply With Quote