New Zenner
- Join Date:
- Apr 2007
- Posts:
- 14
- Plugin Contributions:
- 0
[Done v1.3.9] new products listing not random
My web guy actuially changed the settings and now my site displays items as they are added. If you can ifnd the settings that may help
Views: 11,794
New Zenner
My web guy actuially changed the settings and now my site displays items as they are added. If you can ifnd the settings that may help
Zen Follower
The "config->new listing->sort order" setting appears to just set the sort order of the displayed products, but does not solve our problem of always retrieving a set of sequential products in the first place (product ids 450-460, for example).
I think ThinkNirmal is right. It's the ExecuteRandomMulti function, defined in /public_html/includes/classes/db/mysql/query_factory.php.
It's more complex code than I can figure out at a glance, but I'm studying the function now. The function appears to take the passed SQL query and number, and it retrieves several random products that match the query, up to the specified number of products (if there are enough matches), and returns the array. So we need to tweak that somehow.
Zen Follower
SOLVED!
(I think)
Open /public_html/includes/classes/db/mysql/query_factory.php.
Go to the ExecuteRandomMulti function. Do these 2 steps.
$zp_start_row = zen_rand(0, $obj->RecordCount() - $zf_limit);
to this:
$zp_start_row = zen_rand(0, $obj->RecordCount() - 1);
$zp_result_array = @mysql_fetch_array($zp_db_resource);
Add before it:
$zp_random_row = zen_rand(0, $obj->RecordCount() - 1);
mysql_data_seek($zp_db_resource, $zp_random_row);
I tried this on my store and did many refreshes. It appears to now be showing a random selection of new products within my configured date range. It's a simple fix with no potential side effects that I can foresee, so perhaps if we're lucky it will be included in the next release!
New Zenner
This should be considered in the next upgrade. It should have been a default type of thing.
New Zenner
Thank you so much for this fix!!! I tried it, and it does do a much better job at showing them randomly. I do once in awhile have it show the same product two or three times in the same screen, but I would rather have that now and then, than have it show all 6 products from the same catagory! This has been bugging me for a while now, but just now got around to comming to look for a fix. :) Thanks again!
Zen Follower
doxie:
Thank you so much for this fix!!! I tried it, and it does do a much better job at showing them randomly. I do once in awhile have it show the same product two or three times in the same screen, but I would rather have that now and then, than have it show all 6 products from the same catagory! This has been bugging me for a while now, but just now got around to comming to look for a fix. :) Thanks again!
Glad it helped. I noticed that pretty quickly too. Nothing stops it from picking the same product to display over and over. If you don't have many products qualifying as New, it would be a problem. I have a lot, so it isn't a big deal to me for now.
Unfortunately I couldn't figure out the code around the data structures to try to code something to keep track of which products were picked so far. And I could see it looping like mad for a moment if it got down to only a couple possible new products to pick that it hasn't landed on yet.
I think a more elegant solution would be to create an array of all New products, shuffle it, THEN pick the first 20, or up to 20 (or whatever your constant is set at). Actually, I bet I could do that. I'll let you know if I do.
New Zenner
Old thread, I know....anyway...
After applying this, with 9 new products to show as max, if I have 1 only new product in a category, zen cart shows vertically 9 copies of that product.
If everyone else out there has the same problem, I've found an easy solution. It's at http://www.zen-cart.com/forum/showthread.php?p=899800
New Zenner
Old thread, but I have another thought...
I'm a ZC newbie, but I'm wondering since this fix caused the other problem, which moosesoom found the fix in the previous post...
What are the consequences of the following change instead (in new_products.php).
CHANGE:
if ($new_products_query != '')
$new_products = $db->ExecuteRandomMulti($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);
TO:
if ($new_products_query != '') {
$new_products_query.=" ORDER BY RAND()";
$new_products = $db->ExecuteRandomMulti($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);
}
Seems to work, but would like thoughts from others?!?!
Thanks
Tell staff why this post should be reviewed.