Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

What's new mod

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 02-13-2005, 03:01 PM
 
walteis walteis is offline
 

Advanced Member
  
Join Date: Jan 2003
Location: USA
Posts: 65
 

Default What's new mod

I've created a pretty simple "what's new" modification that someone might be interested in. It displays all the products that were created within a configurable number of days.

First, create a PHP file called newest.php that contains the following code:

Code:
<? // set variables $daterange = 60 * 60 * 24 * $wn; // days in unix time $nowtime = time(); $oldtime = $nowtime - $daterange ; $objects_per_page = $config["Appearance"]["products_per_page"]; // the database query $search_data["products"] = array(); $search_data["products"]["forsale"] = "Y"; $from_tbl[$sql_tbl['featured_products']] = 0; $search_condition = "DATE_SUB(CURDATE(),INTERVAL ". $wn . " DAY) <= from_unixtime(".add_date.") AND "; $mode = "search"; include $xcart_dir."/include/search.php"; $location[]=array("What's New",""); // give the product array to smarty to make it available sitewide. $smarty->assign("newproducts",$products); $smarty->assign("location",$location); $smarty->assign("navigation_script","home.php?wn=$wn"); ?>

Then change home.php to include the following:

Code:
if (!empty($wn)) { include "./newest.php"; $smarty->assign("wn","$wn"); }

I put that right after the Bestsellers code.

Next, you'll need a template called customer/main/newest.tpl

Code:
Visit this area of the store to see all the new items we've added in the last {$smarty.get.wn} days. {if $mode eq "search"} {if $total_items gt "1"} {$lng.txt_N_results_found|substitute:"items":$total_items} {$lng.txt_displaying_X_Y_results|substitute:"first_item":$first_item:"last_item":$last_item} {elseif $total_items eq "0"} {$lng.txt_N_results_found|substitute:"items":0} {/if} {/if} {capture name=dialog} {if $newproducts ne ""} {if $total_pages gt 2} {assign var="navpage" value=$navigation_page} {/if} <TABLE border="0" cellpadding="0" cellspacing="0" width="100%"> {if $sort_fields} {assign var=url value="home.php?wn="|cat:$smarty.get.wn|cat:"&"} <TR> <TD>{include file="main/search_sort_by.tpl" sort_fields=$sort_fields selected=$search_prefilled.sort_field direction=$search_prefilled.sort_direction url=$url} </TD> </TR> {/if} <TR> <TD> {include file="customer/main/navigation.tpl"} {include file="customer/main/products.tpl" products=$newproducts} {include file="customer/main/navigation.tpl"} </TD> </TR> </TABLE> {else} {$lng.txt_no_new|substitute:"XX":$smarty.get.wn} {/if} {/capture} {include file="dialog.tpl" title="New Products" content=$smarty.capture.dialog extra="width=100%"}


Then edit customer/home_main.tpl to include the previous template:

Code:
{elseif $main eq "subscriptions"} {include file="modules/Subscriptions/subscriptions.tpl"} {elseif $wn ne ""} {include file="customer/main/newest.tpl"} {elseif $main eq "catalog" and $current_category.category eq ""} {include file="customer/main/welcome.tpl" f_products=$f_products}


Then I added a config table setting called TFTACustom.wndays, you can call it anything you'd like.

Assuming that you called it that, you can then add a link in the categories.tpl

Code:

This mod works as written with 4.0.7

Walt
__________________
X-cart Gold 4.1.7 on Linux/Apache.
Reply With Quote
  #2  
Old 02-14-2005, 02:18 AM
 
cotc2001 cotc2001 is offline
 

X-Man
  
Join Date: Feb 2003
Location: Shrewsbury, UK
Posts: 2,351
 

Default

I've seen something like this before and very handy it was BUT it's only downfall is if you create a new product and then set it to disabled (because you updating your store and want to enable it later) it will still show in your new product list.

Does yours suffer from that as well or does it obey the disabled rule??
__________________
x-cart 4.0.5 (live and heavily modded)
Server: freebsd
Reply With Quote
  #3  
Old 02-14-2005, 04:26 AM
  ETInteractive.com's Avatar 
ETInteractive.com ETInteractive.com is offline
 

X-Adept
  
Join Date: Dec 2002
Posts: 747
 

Default

$search_data["products"]["forsale"] = "Y";

it will only show if its available for sale.
__________________
ETInteractive.com
X-Cart 3.5.x
Reply With Quote
  #4  
Old 03-24-2005, 07:33 PM
 
tlopez tlopez is offline
 

Newbie
  
Join Date: Oct 2003
Posts: 3
 

Default

Quote:
I've created a pretty simple "what's new" modification that someone might be interested in. It displays all the products that were created within a configurable number of days.

Where do I configure the number of days?

Thanks
__________________
x-cart 4.0.8
Reply With Quote
  #5  
Old 03-25-2005, 02:31 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

Quote:
Originally Posted by tlopez
Quote:
I've created a pretty simple "what's new" modification that someone might be interested in. It displays all the products that were created within a configurable number of days.

Where do I configure the number of days?

Thanks

at the top of the script

Code:
<? // set variables $daterange = 60 * 60 * 24 * $wn; // days in unix time $nowtime = time(); $oldtime = $nowtime - $daterange ; .. .. .. ..
Reply With Quote
  #6  
Old 03-25-2005, 10:55 PM
 
alkhashrami alkhashrami is offline
 

Newbie
  
Join Date: Jan 2005
Location: Abha, Saudi Arabia
Posts: 5
 

Default

Hi,

thanks for this mod

I've tested your mod in 4.0.12 with fashion moasic skin
every thing was good except it appears in the main page which is not good for that skin

SO, how can i configure it to work like if we see a category i.e. not in the main page

thanks again
__________________
X-Cart Gold 4.0.17 (X-AOM, X-FancyCat, FasionMosaic skin)
Operating System Linux
Apache version 1.3.34 (Unix)
PHP version 4.4.1
MySQL version 4.1.13
Reply With Quote
  #7  
Old 03-26-2005, 01:27 AM
 
jeeya jeeya is offline
 

X-Adept
  
Join Date: May 2003
Location: USA
Posts: 807
 

Default

Quote:
Originally Posted by alkhashrami
Hi,

thanks for this mod

I've tested your mod in 4.0.12 with fashion moasic skin
every thing was good except it appears in the main page which is not good for that skin

SO, how can i configure it to work like if we see a category i.e. not in the main page

thanks again


if (!empty($wn)) {
include "./newest.php";
$smarty->assign("wn","$wn");
}


don't put above code in home.php instead put it in catagories.php
__________________
X-Cart Version 4.1.8
Hosted on Linux
Reply With Quote
  #8  
Old 03-26-2005, 04:26 AM
 
alkhashrami alkhashrami is offline
 

Newbie
  
Join Date: Jan 2005
Location: Abha, Saudi Arabia
Posts: 5
 

Default

i did what you said
Quote:
if (!empty($wn)) {
include "./newest.php";
$smarty->assign("wn","$wn");
}

don't put above code in home.php instead put it in catagories.php

but after calling, it returns to home page without any results


any other idea?
__________________
X-Cart Gold 4.0.17 (X-AOM, X-FancyCat, FasionMosaic skin)
Operating System Linux
Apache version 1.3.34 (Unix)
PHP version 4.4.1
MySQL version 4.1.13
Reply With Quote
  #9  
Old 03-28-2005, 11:37 PM
 
alkhashrami alkhashrami is offline
 

Newbie
  
Join Date: Jan 2005
Location: Abha, Saudi Arabia
Posts: 5
 

Default

Hi everybody ,

i tried to modify the this mod to work with my x-cart version and skin,
inspite i'm not a php expert but i depend on comparing similar files and do needed changes then testing on the site.

After 2 days i think that i solve it and this is the mod after modifications:

First, create a PHP file called newest.php that contains the following code:

Code:
<?php require "./auth.php"; require $xcart_dir."/include/categories.php"; // set variables $daterange = 60 * 60 * 24 * $wn; // days in unix time $nowtime = time(); $oldtime = $nowtime - $daterange ; $objects_per_page = $config["Appearance"]["products_per_page"]; // the database query $search_data["products"] = array(); $search_data["products"]["forsale"] = "Y"; $from_tbl[$sql_tbl['featured_products']] = 0; $search_condition = "DATE_SUB(CURDATE(),INTERVAL ". $wn . " DAY) <= from_unixtime(".add_date.") AND "; $mode = "search"; include $xcart_dir."/include/search.php"; $location[]=array(func_get_langvar_by_name("lbl_what_is_new"),""); // give the product array to smarty to make it available sitewide. $smarty->assign("main","newest"); $smarty->assign("newproducts",$products); $smarty->assign("location",$location); $smarty->assign("wn","$wn"); func_display("customer/home.tpl", $smarty); ?>


Next, you'll need a template called customer/main/newest.tpl that contains the following code:

Code:
{capture name=dialog} {if $newproducts ne ""} {$lng.txt_last_added_products} {$smarty.get.wn} {if $smarty.get.wn > 1} {$lng.lbl_days}{else}{$lng.lbl_day}{/if}. {if $mode eq "search"} {if $total_items gt "1"} {$lng.txt_N_results_found|substitute:"items":$total_items} {$lng.txt_displaying_X_Y_results|substitute:"first_item":$first_item:"last_item":$last_item} {elseif $total_items eq "0"} {$lng.txt_N_results_found|substitute:"items":0} {/if} {/if} {if $total_pages gt 2} {assign var="navpage" value=$navigation_page} {/if} <TABLE border="0" cellpadding="0" cellspacing="0" width="100%"> {if $sort_fields} {assign var=url value="home.php?wn="|cat:$smarty.get.wn|cat:"&"} <TR> <TD>{include file="main/search_sort_by.tpl" sort_fields=$sort_fields selected=$search_prefilled.sort_field direction=$search_prefilled.sort_direction url=$url} </TD> </TR> {/if} <TR> <TD> {include file="customer/main/navigation.tpl"} {include file="customer/main/products.tpl" products=$newproducts} {include file="customer/main/navigation.tpl"} </TD> </TR> </TABLE> {else} {$lng.txt_no_added_products|substitute:"XX":$smarty.get.wn} {if $smarty.get.wn > 1} {$lng.lbl_days}{else}{$lng.lbl_day}{/if}. {/if} {/capture} {include file="dialog.tpl" title=$lng.lbl_new_products content=$smarty.capture.dialog extra="width=100%"}


Then edit customer/home_main.tpl to include this code:

Code:
{elseif $wn ne ""} {include file="customer/main/newest.tpl"}


Then, add these lang variables to the database (SQL)

Code:
INSERT INTO xcart_languages VALUES ('US','New products','lbl_new_products','New products','Labels'); INSERT INTO xcart_languages VALUES ('US','These are the products we have added in the last','txt_last_added_products','These are the products we have added in the last','Text'); INSERT INTO xcart_languages VALUES ('US','We are sorry, there are no new added products in the last {{XX}}','txt_no_added_products','We are sorry, there are no new added products in the last {{XX}}','Text'); INSERT INTO xcart_languages VALUES ('US','day','lbl_day','day','Labels');


Finally, you can call this mod through a link e.g:


"wn" indicats the number of days , wn=10 i.e. 10 days


I hope this will be good, and correct me if there is any mistake

thanks for all of you.
__________________
X-Cart Gold 4.0.17 (X-AOM, X-FancyCat, FasionMosaic skin)
Operating System Linux
Apache version 1.3.34 (Unix)
PHP version 4.4.1
MySQL version 4.1.13
Reply With Quote
  #10  
Old 03-29-2005, 04:11 AM
 
sabrina sabrina is offline
 

Advanced Member
  
Join Date: Feb 2003
Location: Indianapolis, IN., USA
Posts: 53
 

Default

If i try this link:
http://www.indyplaza.com/catalog/newest.php?wn=10

I got:

Page not found!
The requested page does not exist or you are not allowed to access it!


If i try this link:
http://www.indyplaza.com/catalog/newest.php

I got:

INVALID SQL: 1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ') <= from_unixtime(add_date) AND xcart_pricing.productid=xcart_
SQL QUERY FAILURE: SELECT COUNT(xcart_products.productid), MIN(xcart_pricing.price) as price , xcart_products_lng.product as product_lng, xcart_products_lng.descr as descr_lng, xcart_products_lng.full_descr as fulldescr_lng, IF(xcart_variants.variantid IS NOT NULL,'Y','') as is_variant, IF(xcart_classes.classid IS NOT NULL,'Y','') as is_product_options, v_pricing.price as v_price FROM xcart_products, xcart_pricing , xcart_featured_products, xcart_products_categories, xcart_categories LEFT JOIN xcart_products_lng ON xcart_products_lng.productid = xcart_products.productid AND xcart_products_lng.code = 'US' LEFT JOIN xcart_classes ON xcart_classes.productid = xcart_products.productid LEFT JOIN xcart_variants ON xcart_variants.productid = xcart_products.productid LEFT JOIN xcart_pricing as v_pricing ON v_pricing.variantid = xcart_variants.variantid AND v_pricing.quantity = 1 AND v_pricing.membership IN ('','') WHERE DATE_SUB(CURDATE(),INTERVAL DAY) <= from_unixtime(add_date) AND xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.membership IN ('','') AND (xcart_pricing.variantid = 0 OR (xcart_variants.variantid = xcart_pricing.variantid)) AND xcart_products_categories.productid=xcart_products .productid AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.membership IN ('','') AND xcart_products.forsale='Y' GROUP BY xcart_products.productid

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/indypla/public_html/catalog/include/func.php on line 102
__________________
X-CART GOLD: 4.0.14

Operating system Linux
Apache version 1.3.33 (Unix)
PERL version 5.8.1
PHP version 4.3.10
MySQL version 4.0.22-standard
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:58 AM.

   

 
X-Cart forums © 2001-2020