X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Newest Products (https://forum.x-cart.com/showthread.php?t=1084)

funkydunk 01-01-2003 07:24 AM

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

B00MER 01-01-2003 09:31 PM

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! :D

funkydunk 01-01-2003 11:41 PM

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. :lol:

cyberactive 01-01-2003 11:45 PM

I runs smoothly over here.

And fast too.... :D

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

cyberactive 01-02-2003 04:59 AM

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.

herberr 01-05-2003 03:30 AM

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 ?

funkydunk 01-05-2003 06:33 AM

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

Cheers

herbster 01-27-2003 08:10 AM

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 ???

funkydunk 01-27-2003 08:20 AM

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

funkydunk 01-27-2003 11:10 PM

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";

RazorWriter 05-05-2003 09:34 AM

Has anyone tried to add this newest products function to Version 3.3 of X-cart? I can't get it to work on the newer version. Also, how would one plug this function into another page?

funkydunk 05-05-2003 09:59 AM

Hi,

Got it working on 3.3.3 and 3.3.4 and 3.3.5

Can you post the code that you are using or the errors that you are getting?

jeeya 06-21-2003 08:33 PM

How to creat Php files??
 
HI,
well this may be a stupid question but I need answer, How to create a new php file?? and for tpl, I have to just go to customer and put newest.tpl in new and create file right????


Thanks.

funkydunk 06-22-2003 11:49 AM

You need to do it with a text editor then upload the file using ftp to the directory specified. Not possible through the admin centre.

jeeya 06-22-2003 04:43 PM

ok
 
ok.

So I can use wordpad or microsoft work and paste the code from the top and save file as specials.tpl and upload it through administration area like I have to in customer file area, Right?

Thanks.

funkydunk 06-22-2003 10:50 PM

if you are creating a php file it should be specials.php

jeeya 07-05-2003 10:15 AM

ok
 
so it will be specials.php

than i will go to my ftp account
and upload this file

Or do I need any specific directory to define?


I am using version 3.4.0

Sorry for questions, but I never done this before.
Thanks :D

jeeya 07-05-2003 04:09 PM

ok
 
ok I have tried everything and I dont know what happened wrong but you can see here, it does not show anything

Version is 3.4.0

thanks

redace 07-09-2003 07:32 PM

possible alternate page?
 
Having the newly added items is nice, but it seems to clutter up the main page especially if there are already some featured items already showing.

How about having a seperate menu selection in either the category or help menu or a custom menu to allow the customer to click on the "NEW" item button, and then it would display just the new items with the newest query.

I'll take a look into it of it's not already been done. :wink:

funkydunk 07-09-2003 10:29 PM

Agreed :)

Put together a few mods recently where the newest products are on a new page complete with navigation and clickable links to show the newest in the last week, two week, month etc. Then link tothis from the home page menu as you describe.

genekurtz 07-09-2003 10:47 PM

Is this supposed to work on 3.4.2 or is it just for the older version? Cyberactive...nice site.

funkydunk 07-09-2003 11:34 PM

I haven't tested this on a 3.4.x site but there is no reason that it shouldn't work. :)

DataViking 08-09-2003 05:59 PM

I got it
 
Quote:

Originally Posted by cyberactive
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.


nice change, i try the first query and my home page was loaded with pictures.

thanks again, very nice mod.

by the way do anyone have a way to add this mod to a link insted of the front page?

rodneyw 08-25-2003 12:00 PM

Just noticed I am having some problems with the script on 3.4.4

It is probablly having to do some other modifications I have done but here are my issues. If anyone would like to help me sort them out I can put the files up.

1. I modified the newest.tpl file to include featured="Y" so that I could use the multi-colum format provided by using the products_t.tpl file.

I am now getting duplicate listings, if I chose to show 6 products instead of 6 products I am getting 2 sets of 3 products.

2. The Buy Now buttom is NOT working for the NEWEST products listed by the mod. The Featured listings are still working properly though.

When I view the source after the page is displayed everything seems to be correct:
Code:

<table width=100% style="border-style: solid; border-width: 1">
<tr>
<td><center>
<a href=product.php?productid=2591&cat=&page=><font size="1">See Details</font>

[img]../image.php?productid=2591[/img]</a>
</center></td>
<td valign=top>
OPI - Sand-erella</font>
<font size=1>


Sand-erella


</font>
<hr size=1 noshade width=175 align=left>

<font class=ProductPrice>Our Price: $ 5.67</font>
<table border=0 width=100% cellpadding=0 cellspacing=0>
<FORM name="orderform_2591_1061578337" method=post action="cart.php?mode=add">
<input type=hidden name=productid value="2591">
<input type=hidden name=cat value="">
<input type=hidden name=page value="">
<tr>
<td height=25 nowrap>Quantity

<select name=amount>

<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
</select>
</td>
</tr>
<tr>
<td width=100% height=25 background-color:#FFFFFF" onMouseover="this.style.backgroundColor='#FFcc00';" onMouseout="this.style.backgroundColor='#FFFFFF';">
<input type=hidden name=mode value=add>
<font class=FormButton>[img]../skin1/images/go.gif[/img]Buy Now</font>
</td>
</tr>
</FORM>
</table>


help ... anyone?

rodneyw 08-25-2003 04:34 PM

never mind .. I found the error of my ways.

It seems that If I need to figure out any issues I have, I need to just go ahead and post it first becasue it never fails I figure it out before anyone takes pity on me and helps me :roll: :wink:

Sure makes it a tough way to learn but it sticks

jeeya 09-03-2003 08:26 PM

.
 
Is there a Way to Display New added Products Catagorywise - If customer visits specific catagory he can see new products added in that specific main catagory?

funkydunk 09-03-2003 10:49 PM

yes :)

GregCroft 10-23-2003 06:39 PM

Quote:

Originally Posted by funkydunk
yes :)


Does that mean we have to buy your module?

shasan 10-23-2003 08:57 PM

Was anyone successful in getting a multi-column display for this mod. I'm still trying to figure that one out.

any help would be great.

Thanks to all yallz.

funkydunk 10-23-2003 10:29 PM

Quote:

Originally Posted by shasan
Was anyone successful in getting a multi-column display for this mod. I'm still trying to figure that one out.

any help would be great.

Thanks to all yallz.


The mod on my site uses the normal product listing layout from the rest of your site so if you are using multi column it will display like that.

shasan 10-23-2003 10:52 PM

thx funkydunk,

unfortunately I only have multi-column on for the featured products, the rest of the site uses single column :(

I was thinking I could probably use the same kind of logic that the featured products module uses, but I have no idea where, so I just used your mod to display 1 product :) works fine for me for now until I (or someone else) figures it out.

abeight 11-08-2003 08:15 AM

Great mod, I just installed it at http://www.pixeloutlet.com. My only question is, how can I put a title in the box header?

B00MER 11-08-2003 08:35 AM

Create the entry lbl_new_products in your languages in the admin ;)

abeight 11-08-2003 08:48 AM

Aha! Thank you!

adpboss 11-08-2003 09:15 AM

Abeight,

nice looking site btw.

Very attractive design IMHO.

abeight 11-08-2003 10:36 AM

Thanks, adpboss!

Since I added this mod, all of our static pages are blank. When I login to the admin area, the code for the pages is still there, but it won't show in the preview. An example, is here: http://www.pixeloutlet.com/xcart/customer/pages.php?pageid=8. This page used to have a list of contributors. Any ideas?

adpboss 11-08-2003 10:40 AM

try flushing your templates_c folder.

I am assuming that you are using 3.4.x (tsk tsk, should be in your sig).

Go to Summary (in the admin), and scroll to the bottom of the page.

Clear templates cache.

Let us know if that works.

abeight 11-08-2003 10:46 AM

Thanks, didn't think to put that in my sig. Clearing the templates cache didn't fix it.

adpboss 11-08-2003 10:49 AM

Time to hit that search button, I know there are a lot of posts on this.

Good Luck!

nfc5382 11-10-2003 02:13 PM

works great in 3.4.4, thanks!


All times are GMT -8. The time now is 06:02 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.