News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

[SOLVED] Randomize product order

Started by sagaranvekar, November 08, 2018, 21:44:27 PM

Previous topic - Next topic

sagaranvekar

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.

GJC Web Design

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
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation


sagaranvekar

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.