Author Topic: [SOLVED] Randomize product order  (Read 183 times)

sagaranvekar

  • Beginner
  • *
  • Posts: 26
[SOLVED] Randomize product order
« 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.
 

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8586
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Randomize product order
« Reply #1 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
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3528
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Randomize product order
« Reply #2 on: November 10, 2018, 01:18:42 am »

sagaranvekar

  • Beginner
  • *
  • Posts: 26
Re: Randomize product order
« Reply #3 on: November 10, 2018, 15:45:50 pm »
Thank you very much for the replies.

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
Code: [Select]
case 'pc.ordering':
$orderBy = ' ORDER BY `pc`.`ordering` '.$filterOrderDir.', p.`virtuemart_product_id` '.$filterOrderDir;
$joinCategory = TRUE;
break;

I changed this to:

Code: [Select]
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.