Forums / Templates, Stylesheets, Page Layout / Where does ZC pull the products in a category from database?

Where does ZC pull the products in a category from database?

Views: 656

Results 1 to 4 of 4
4 Aug 2011, 1:59 PM
#1
buddhaflow avatar

buddhaflow

New Zenner

Join Date:
Mar 2009
Posts:
41
Plugin Contributions:
0

Where does ZC pull the products in a category from database?

Hi, I have a most vexing problem.

I want to display the products in totally random order. Every time they refresh, I want it to show totally different products. I am selling t-shirts and bumper stickers, and I really don't want it showing the same few products at the top every time.

I hate to bother the forum, but I have spent HOURS digging through the guts of ZC, grep'ping for every vaguely related term, etc.

I thought it would be so easy - just find the SQL statement where it grabs the products to display, add an 'order by rand()' to the end of it, presto!

But I just can't find this SQL statement ANYWHERE!! It is driving me bananas.

I thought, for instance, it would be in /includes/classes/db/mysql/define_queries.php. But it doesn't seem to be. I also looked through all the core files, the function defines, the default template, the template I am using, etc. etc. I just don't know where else to look.

Could someone please enlighten me as to where this logic might reside?

Thank you!
Sasha Shepherd

4 Aug 2011, 2:13 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Where does ZC pull the products in a category from database?

Exactly which display component are you referring to? Are you talking about a "featured products" box? or a "specials" box? or the product-listing within each category? Are you saying you wish to completely ignore the customer's sort-preference selected in the pulldown? and ignore the default sort-order you've set within your admin?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Aug 2011, 2:25 PM
#3
buddhaflow avatar

buddhaflow

New Zenner

Join Date:
Mar 2009
Posts:
41
Plugin Contributions:
0

Re: Where does ZC pull the products in a category from database?

Ah! I cracked it!!!!

/includes/index_filters/default_filter.php

I sure didn't think to look in that folder :(

I just did a search in the file for everyhting that said '$sql_listing .='

Commented all of it out.

Then, wrote a single statement:

$listing_sql .= " order by rand()";

That solved it. Now all products display in random order :)

4 Aug 2011, 2:26 PM
#4
buddhaflow avatar

buddhaflow

New Zenner

Join Date:
Mar 2009
Posts:
41
Plugin Contributions:
0

Re: Where does ZC pull the products in a category from database?

Basically, in every category view, I wanted to totally ignore any sort preferences (my template disabled them for the customer anyway), and ONLY do random. It worked a charm :)