You are here:  » Displaying random products

Active Forum Topics


Displaying random products

Submitted by macland on Thu, 2016-09-29 08:11 in

On the site {link saved} I have a site with gift ideas, some landing pages and hundreds of thousands of products.

I have an "Idea Generator" where I display random products, right now using the display from randomexternal.php (even though it an all pricetapestry site).

I would like to make this idea generator as advanced as possible, so that it will become more useful to the user.

Would it then be smarter for me to display the products in a different way, using some other code - perhaps reusing something from the category display?

I would like to
* Display a number of products at random
* Include filters, like price and gender etc.
* Be able to deeplink to those filters (so from my landing page with "gift for kids" I can link directly to the Idea Generator with the attribute gender set for "kids"
* Be able to "reload" the display. So that if I have set some attributes I display 40 products, but then I can click reload and the attribute filters stay the same but the display loads 40 new products.

I hope it makes sense what I mean :-)
Thank you very much in advance

Submitted by support on Thu, 2016-09-29 09:18

Hi,

One thing to do would be to add a "random" sort operator and then link to search.php with any combination of filters to create ideas for different circumstances, using a query of "bw:" (which returns all products) with sort=random. To give this a go, edit search.php and look for the following code at line 85:

    $orderByDefault["priceDesc"] = "minPrice DESC";

...and REPLACE with:

    $orderByDefault["priceDesc"] = "minPrice DESC";
    $orderByDefault["random"] = "RAND(".date("z").")";

...and then the following code at line 95:

    $orderByFullText["priceDesc"] = "minPrice DESC";

...and REPLACE with:

    $orderByFullText["priceDesc"] = "minPrice DESC";
    $orderByFullText["random"] = "RAND(".date("z").")";

And then link using, for example;

/search.php?q=bw:&sort=random

(bw: is the "begins with" operator, and with nothing after the ":" returns all products)

Alternatively you could use keywords, and of course filters e.g.

/search.php?q=DVD&categoryFilter=Comedy&sort=random

Using date("z") (day of the year) as the seed value for MySQL's RAND() function will ensure that the result order, whilst random will be constant, but change daily.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by macland on Thu, 2016-09-29 11:18

Thank you very much!

I have just made it without date so it's completely random each time in order to enable the "get new ideas".

I have added my custom fields as filters as per http://www.pricetapestry.com/node/4788

It works fine in the URL when I enter it manually, but I can't get the filter button to work, perhaps because I don't use sidebar filters.

I have searched and searched and read a lot about sidebar filters, but can't find a code to enable it. Do you have a link to such a thread as it would be great to move all filtering into the sidebar, especially since I will have many filters?

The same with grid view - right now I rather like the look at {link saved}, could be great to have that in search display results as well.

And again thank you so much for your great support

Submitted by support on Thu, 2016-09-29 11:52

Hi,

The sidebar filters that was available was for an earlier distribution, apologies for the confusion. I'll prepare a version for 15/09A - if you could drop me an email i'll forward it to you, with results displayed as a grid.

I have all the code, just a case of pulling it all together...

Cheers,
David.
--
PriceTapestry.com