VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: sagaranvekar on November 08, 2018, 21:44:27 PM

Title: [SOLVED] Randomize product order
Post by: sagaranvekar on November 08, 2018, 21:44:27 PM
Hello,

I have a Joomla 3.8.11 website with Virtuemart 3.2.14 website.

I am using a menu item with "Top level category" setting to display all available products in my shop.
When i go to vm-> Config -> Product order settings, currently "Default product sort order" is set to "Ordering, name" order. But there is no setting as "random".

I know there is product module that can be used to show random products, but i can't use it as already there is override used for that module to show products in carousel. So, that option is not available.

So, can anyone help me achieve this? I can make changes to core file if needed but i am not sure which file to edit.
So, any help will be much appreciated.

Thanks.
Title: Re: Randomize product order
Post by: GJC Web Design on November 08, 2018, 23:12:54 PM
administrator\components\com_virtuemart\models\product.php

function sortSearchListQuery()

somewhere there.. maybe even the parameter $group   - try 'random'

see code if ($group) { ~ line 623
Title: Re: Randomize product order
Post by: Studio 42 on November 10, 2018, 01:18:42 AM
Perhaps my module https://shop.st42.fr/en/products/products-any-ways.htm
Title: Re: Randomize product order
Post by: sagaranvekar on November 10, 2018, 15:45:50 PM
Thank you very much for the replies.

Quote from: GJC Web Design on November 08, 2018, 23:12:54 PM
administrator\components\com_virtuemart\models\product.php

function sortSearchListQuery()

somewhere there.. maybe even the parameter $group   - try 'random'

see code if ($group) { ~ line 623

@GJC Web Design:
Thank you very much for taking to right file. The suggested change was not working as it took me to "//Group case from the modules". So, probably, that group case is for vm product module. I wanted it for component. So, i searched in the same file & successfully randomized product order.


For those who are looking for this, please note that, i have a vm store in catalog mode. So, i went to :
vm-> Config -> Product order settings and used "Default product sort order" to "Ordering" (not Ordering, Name)
Then in administrator\components\com_virtuemart\models\product.php
in function sortSearchListQuery, at line number 535, look for comment // special  orders case
as i chose 'Ordering' in vm config, i went to line number 564 where we have

case 'pc.ordering':
$orderBy = ' ORDER BY `pc`.`ordering` '.$filterOrderDir.', p.`virtuemart_product_id` '.$filterOrderDir;
$joinCategory = TRUE;
break;


I changed this to:


case 'pc.ordering':
$orderBy = 'ORDER BY RAND()';
$joinCategory = TRUE;
break;


So, if you choose any other sort setting like Product name or Product price in vm config, you will have to make changes in respective switch case.