Thread: Newest Products
View Single Post
  #206  
Old 02-28-2008, 08:21 AM
 
erickim erickim is offline
 

Newbie
  
Join Date: Jan 2008
Posts: 6
 

Default Re: Newest Products

Quote:
Originally Posted by pavant
I love this mod but it wasn't set up for 4.1.x versions of xcart so I tried to make it work with my 4.1.8. I have it set to show new products added within the last 90 days on the home page only. Here is what I have so far:

1. Create file newest.php in the xcat home directory.
PHP Code:
<?php
#
# $Id: newest.php 2007/07/22 $
#
// set variables
$daterange 7776000// 60 * 60 * 24 * 90 days in unix time
$nowtime time();
$oldtime $nowtime $daterange ;
 
# Get new products data and store it into $newproducts array
#
if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }
#
# Select from products table
#
$user_account['membershipid'] = !empty($user_account['membershipid'])?$user_account['membershipid']:0;
$old_search_data $search_data["products"];
$old_mode $mode;
$old_page $page;
$search_data["products"] = array();
$search_data["products"]["forsale"] = "Y";
$search_data["products"]["avail"] = "> 0";
$search_data["products"]["add_date"] = "> " $oldtime "";
$search_data["products"]["add_date"] = "< " $nowtime "";
$search_data["products"]["sort_condition"] = "$sql_tbl[products].add_date DESC";
$REQUEST_METHOD "GET";
$mode "search";
include 
$xcart_dir."/include/search.php";
$search_data["products"] = $old_search_data;
x_session_save("search_data");
$mode $old_mode;
$page $old_page;
unset(
$old_search_data$old_mode$old_page);
$smarty->clear_assign("newproducts");
$smarty->assign("newproducts",$products);
$search_data '';
$products = array();
unset(
$search_data$products);
?>
2. Modify file home.php in the xcart home directory to add code for newest.php

PHP Code:
if (empty($products)) {
include 
"./featured_products.php";
}
if (empty(
$products) and empty($current_category)) {
include 
"./newest.php";



3. Modify statement in the home_main.tpl template in the skin1/customer directory to read as follows:

{elseif $main eq "catalog" && $current_category.category eq ""}
{include file="customer/main/welcome.tpl" f_products=$f_products newproducts=$newproducts}


4. Create newest.tpl template in the /skin1/customer/main directory.

{* $Id: newest.tpl,v 1.13 2002/05/20 06:55:20 lucky Exp $ *}
{capture name=dialog}
{if $newproducts ne ""}
{include file="customer/main/products.tpl" products=$newproducts}
{/if}
{/capture}
{include file="dialog.tpl" title="New Products" content=$smarty.capture.dialog extra="width=100%"}



5. Modify the welcome.tpl template in the /skin1/customer/main directory.

{if $f_products ne ""}
{include file="customer/main/featured.tpl" f_products=$f_products}
{/if}
{if $newproducts ne ""}
{include file="customer/main/newest.tpl" newproducts=$newproducts}
{/if}
{if $f_products eq "" && $newproducts eq ""}
<img src="{$ImagesDir}/customer_images/welcome.jpg" alt="" />
{/if}


I hope this helps some of the xcart 4.1 sites. I make no promises that this code will work with your site; each environment is different and your code may function differently especially if it has already been moded. I can't provide any support for this mod. Install only if you have the resources to fix any problems that may occur.

I followed your(Pavant's) codes posted #186, it works fine except one thing.
It shows the products alphabetical order, not by newest.
I have 4.1.9 xcart. Could you help me what is wrong with this?
Or anybody help me?


Thank you.
__________________
x-cart gold 4.1.9
Reply With Quote