Zen Cart Logo
Forums / Customization from the Admin / Sort Order Of New Products On Main Page

Sort Order Of New Products On Main Page

Views: 7,469

Results 1 to 12 of 12
1 Sep 2023, 2:13 PM
#1
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Sort Order Of New Products On Main Page

Hi,

I am looking to change the sort order for the New Products that display on the Main Page and have tried changing this through Admin-> Config->New Listing without any success.

I am assuming this needs to be coded in to a .php file. Would someone be able to point me to which file to change and the code necessary to display these products in a date added descending order?

Thank you in advance for your help!

1 Sep 2023, 4:17 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,690
Plugin Contributions:
56

Re: Sort Order Of New Products On Main Page

To confirm: you're using the new products centerbox on the home page (You have Admin >Configuration > Index Listing > Show New Products on Main Page set to a non-zero value) and you want to change the order in which these products are sorted - correct?

What template are you using?

1 Sep 2023, 5:01 PM
#3
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Thanks for your reply swguy!

Yes, I am using the standard default zen cart of v.1.5.8 and in Admin->Config->Index Listing->Show New Products on Main Page is set to 1.

Yes, you are correct that I would like to change the order in which the products are sorted in this New Products area on the home page. It currently is sorting as random and I would like to sort them as date added descending.

Thanks for your help!

1 Sep 2023, 5:46 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,690
Plugin Contributions:
56

Re: Sort Order Of New Products On Main Page

Still need your template - is it bootstrap or something else?

1 Sep 2023, 10:04 PM
#5
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: Sort Order Of New Products On Main Page

ok, not the easiest thing to do but not the hardest either.

copy from:

includes/modules/new_products.php

to:

includes/modules/YOUR_TEMPLATE/new_products.php

this copied file is the one you want to modify.

now, i will use this file as a template to show you lines to add and modify.

https://github.com/zencart/zencart/blob/v200/includes/modules/new_products.php

// right after line 17 add:
$order_by = ' ORDER BY p.products_date_added DESC ';

// modify line 27 to:
AND p.products_status = 1 " . $display_limit . $order_by;

//modify line 41 to:
AND p.products_id IN (" . $list_of_products . ") . $order_by " ;

// modify line 47 to:
$new_products = $db->Execute($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);

//modify line 93 to:
$new_products->MoveNext();

best.

2 Sep 2023, 12:56 PM
#6
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Hi swguy,

I am using the Default Template on my site so the files used are the standards that come stock with v.1.5.8

Thanks!

2 Sep 2023, 12:58 PM
#7
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Thank you for your help carlwhat!

I appreciate your detailed coding you have given and I will make these changes later today.

Thanks again....much appreciated!

2 Sep 2023, 1:23 PM
#8
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Thanks again for your help carlwhat! I just applied this coding and it works perfectly......just what I was trying to achieve.

Very much appreciate your help!

2 Sep 2023, 3:08 PM
#9
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: Sort Order Of New Products On Main Page

NWCE:

Thanks again for your help carlwhat! I just applied this coding and it works perfectly......just what I was trying to achieve.

Very much appreciate your help!

:thumbsup:

3 Sep 2023, 12:41 PM
#10
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Hi carlwhat,

I had one minor bug crop up with this sort order change. Here is the Debug error:

PHP Fatal error: 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 '. ORDER BY p.products_date_added DESC LIMIT 50' at line 6 :: SELECT DISTINCT p.products_id, p.products_image, pd.products_name, p.products_price, p.master_categories_id
FROM zen_products p, zen_products_description pd
WHERE p.products_id = pd.products_id
AND pd.language_id = 1
AND p.products_status = 1
AND p.products_id IN (2476,2477,2478,2479,2480,2481,2482,2483,2484,2485,2486,2487,2488,2489) . ORDER BY p.products_date_added DESC LIMIT 50 ==> (as called by) /shop/includes/modules/customname/new_products.php on line 48 <== in /shop/includes/classes/db/mysql/query_factory.php on line 667.

In Admin-> Config I have set the Max Number of New Products to Show On Main Page to 50....whereas I only have 14 to show.

Any ideas why it is throwing this error??

Thanks.

3 Sep 2023, 2:33 PM
#11
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: Sort Order Of New Products On Main Page

my mistake.

// line 41 above from:
AND p.products_id IN (" . $list_of_products . ") . $order_by ";

// to
AND p.products_id IN (" . $list_of_products . ")" . $order_by;

// alternatively this should work as well:
AND p.products_id IN (" . $list_of_products . ") $order_by";

best.

3 Sep 2023, 2:55 PM
#12
nwce avatar

nwce

Zen Follower

Join Date:
Oct 2009
Posts:
444
Plugin Contributions:
0

Re: Sort Order Of New Products On Main Page

Thanks again for your help carlwhat!

I will make this change!