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

Newest Products

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 01-01-2003, 07:24 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default Newest Products

Cyberactive and I have been working on a module that shows up products added into the shop over the last week and have come up with the code below to show this on your home page.

Try this - it works fine and dandy in 3.2.2

First create a new php file customer/newest.php
Code:
<? // set variables $daterange = 604800; // 60 * 60 * 24 * 7 days in unix time $nowtime = time(); $oldtime = $nowtime - $daterange ; // the database query $query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid AND add_date > " . $oldtime . " AND add_date < " . $nowtime . " ORDER BY xcart_products.productID DESC LIMIT 0,5 "; // give the product array to smarty to make it available sitewide. $newproducts = func_query($query); $smarty->assign("newproducts",$newproducts); ?>

This is set to select 5 products added within the last week but you can change the timespan to whatever you like by changing the daterange variable. This is unix time so is calculated in seconds.

Second, add into the customer/home.php file after the require featured.php bit

Code:
require "./newest.php";

Third, create a newest.tpl template:
Code:
{* $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} {else} {$lng.txt_no_new} {/if} {/capture} {include file="dialog.tpl" title=$lng.lbl_new_products content=$smarty.capture.dialog extra="width=100%"}

You will note in here two extra fields to the languages part, one in labels for the heading to the section then a second one to show if there are no new prodoucts.

Fourth - amend home_main.tpl to
Code:
{if $smarty.get.mode eq "subscribed"} {include file="main/subscribe_confirmation.tpl"} {elseif $smarty.get.mode eq "unsubscribed"} {include file="main/unsubscribe_confirmation.tpl"} {elseif $main eq "search"} {include file="customer/main/search_result.tpl"} {elseif $main eq "advanced_search"} {include file="customer/main/advanced_search.tpl"} {elseif $main eq "cart"} {include file="customer/main/cart.tpl"} {elseif $main eq "wishlist"} {if $active_modules.Wishlist ne ""} {include file="modules/Wishlist/wishlist.tpl"} {/if} {elseif $main eq "anonymous_checkout"} {include file="customer/main/anonymous_checkout.tpl"} {elseif $main eq "order_message"} {include file="customer/main/order_message.tpl"} {elseif $main eq "checkout"} {include file="customer/main/checkout.tpl"} {elseif $main eq "product"} {include file="customer/main/product.tpl" product=$product} {elseif $main eq "giftcert"} {include file="modules/Gift_Certificates/giftcert.tpl"} {elseif $main eq "subscriptions"} {include file="modules/Subscriptions/subscriptions.tpl"} {elseif $main eq "catalog" and $current_category.category eq ""} {include file="customer/main/welcome.tpl" f_products=$f_products newproducts=$newproducts} {elseif $main eq "catalog"} {include file="customer/main/subcategories.tpl" cat=$cat} {else} {include file="common_templates.tpl"} {/if}

Fifth and finally - amended the welcome.tpl template to the following:
Code:
{* $Id: welcome.tpl,v 1.21 2002/09/10 12:36:34 zorg Exp $ *} {if ($active_modules.Greet_Visitor ne "") AND ($smarty.cookies.GreetingCookie ne "")} <h3>{$lng.lbl_welcome_back}, {$smarty.cookies.GreetingCookie} </h3> {else} <h3>{$lng.lbl_welcome_to} { $config.Company.company_name }</h3> {/if} {$lng.txt_welcome} {if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"} {include file="modules/Bestsellers/bestsellers.tpl"} {/if} {include file="customer/main/featured.tpl" f_products=$f_products} {include file="customer/main/newest.tpl" newproducts=$newproducts}

Not sure whether this works with 3.3.

Enjoy
__________________
ex x-cart guru
Reply With Quote
  #2  
Old 01-01-2003, 09:31 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Nice work funky dunk, maybe I can implement this soon in some of my upcomming carts. From the looks of it though, should work great!
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #3  
Old 01-01-2003, 11:41 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Cyberactive has taken it on further now - full thread is http://forum.x-cart.com/viewtopic.php?t=1402&highlight=

He has put it in place on his site and it looks really good - would make a good standard module if the x team are watching.
__________________
ex x-cart guru
Reply With Quote
  #4  
Old 01-01-2003, 11:45 PM
 
cyberactive cyberactive is offline
 

Senior Member
  
Join Date: Sep 2002
Location: The Netherlands
Posts: 115
 

Default

I runs smoothly over here.

And fast too....

I've just changed the query a bit to randomize the results.
__________________
Dennis

Shop @ http://www.cyberlease.nl
Version shop: 3.4.4 (shop is NOT life anymore)
Mods:
- Dutch language
- Changed payment methods and shipping methods
- Package tracking system for Dutch TPGpost.
Reply With Quote
  #5  
Old 01-02-2003, 04:59 AM
 
cyberactive cyberactive is offline
 

Senior Member
  
Join Date: Sep 2002
Location: The Netherlands
Posts: 115
 

Default

The randomise query is
Code:
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid AND add_date > " . $oldtime . " AND add_date < " . $nowtime . " ORDER BY RAND() LIMIT 5 ";

Just change the number after LIMIT to show more or less products.

Good luck.
__________________
Dennis

Shop @ http://www.cyberlease.nl
Version shop: 3.4.4 (shop is NOT life anymore)
Mods:
- Dutch language
- Changed payment methods and shipping methods
- Package tracking system for Dutch TPGpost.
Reply With Quote
  #6  
Old 01-05-2003, 03:30 AM
 
herberr herberr is offline
 

Newbie
  
Join Date: Jan 2003
Posts: 5
 

Default Re: Newest Products

Quote:
Originally Posted by funkydunk
Cyberactive and I have been working on a module that shows up products added into the shop over the last week and have come up with the code below to show this on your home page.

Not sure whether this works with 3.3.

Enjoy

Funkydunk, i copied your code (which looks good), but it doesn't run into my site.

I got the following errormessage at the top of the page :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site6/fst/var/www/html/config.php on line 288

And i got the following errormessage at the footer of the page :
Warning: Smarty error: unable to read template resource: "customer/main/newest.tpl" in /home/virtual/site6/fst/var/www/html/Smarty-2.1.1/Smarty.class.php on line 546
What did I wrong ?
Reply With Quote
  #7  
Old 01-05-2003, 06:33 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Can you post your exact code into the forum and I will have a peek.

Cheers
__________________
ex x-cart guru
Reply With Quote
  #8  
Old 01-27-2003, 08:10 AM
 
herbster herbster is offline
 

Member
  
Join Date: Jan 2003
Posts: 20
 

Default

Quote:
Originally Posted by funkydunk
Can you post your exact code into the forum and I will have a peek.

Cheers

We are running version 3.1.3. Is that the cause of my problem ???
Reply With Quote
  #9  
Old 01-27-2003, 08:20 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

I would say yes... if you upgraded to 3.2.4 or 3.3.1 this would be workable. There seem to be quite a few changes from 3.1 to 3.2 onwards
__________________
ex x-cart guru
Reply With Quote
  #10  
Old 01-27-2003, 11:10 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Just a quick note that if you want this to show up when you are in other sections of the shop, like help.php cart.php then the thing to do is include the newest.php file in those files as per the instructions for home.php.

Code:
require "./newest.php";
__________________
ex x-cart guru
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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:19 AM.

   

 
X-Cart forums © 2001-2020