- Posts: 10
- Thank you received: 0
Please post all pre-sales questions of all products on this forum
Can front page products be displayed randomly
- Tony Powers
- Topic Author
- Offline
- New Member
-
Less
More
8 years 5 months ago #97027
by Tony Powers
Can front page products be displayed randomly was created by Tony Powers
Hi
On the EShop front page I just want products to be displayed but I want this to be a random collection of any of the products rather than only Featured products (which seems to be all I can get to display).
Is this possibleconfiguration? If not then can you please tell me where the code for the front page is so I can change it myself.
Regards
Tony
On the EShop front page I just want products to be displayed but I want this to be a random collection of any of the products rather than only Featured products (which seems to be all I can get to display).
Is this possibleconfiguration? If not then can you please tell me where the code for the front page is so I can change it myself.
Regards
Tony
Please Log in or Create an account to join the conversation.
- Giang Dinh Truong
-
- Offline
- Administrator
-
8 years 5 months ago #97059
by Giang Dinh Truong
Replied by Giang Dinh Truong on topic Can front page products be displayed randomly
Hello Tony,
This is not supported now. If you want to change the code, then you should check the file components/com_eshop/views/frontpage/view.html.php
Hope that this is useful.
Sincerely, Giang
This is not supported now. If you want to change the code, then you should check the file components/com_eshop/views/frontpage/view.html.php
Hope that this is useful.
Sincerely, Giang
The following user(s) said Thank You: Tony Powers
Please Log in or Create an account to join the conversation.
- Tony Powers
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 10
- Thank you received: 0
8 years 5 months ago #97067
by Tony Powers
Replied by Tony Powers on topic Can front page products be displayed randomly
Many thanks thats helpful will have a crack myself
Please Log in or Create an account to join the conversation.
- Tony Powers
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 10
- Thank you received: 0
8 years 5 months ago #97069
by Tony Powers
Replied by Tony Powers on topic Can front page products be displayed randomly
Actually there is no frontpage folder within the components/com_eshop/views folder so I am still not able to do this
Regards
Tony
Regards
Tony
Please Log in or Create an account to join the conversation.
- Tony Powers
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 10
- Thank you received: 0
8 years 5 months ago - 8 years 5 months ago #97071
by Tony Powers
Replied by Tony Powers on topic Can front page products be displayed randomly
Doh! Was in the administration folder found it now!
Last edit: 8 years 5 months ago by Tony Powers.
Please Log in or Create an account to join the conversation.
- Tony Powers
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 10
- Thank you received: 0
8 years 5 months ago #97077
by Tony Powers
Replied by Tony Powers on topic Can front page products be displayed randomly
So if anyone else wants to do this this is what I did (better suggestions welcome)
components/com_eshop/views/frontpage/view.html.php
Change the call aat around line 76 to:
$products = RADModel::getInstance('Products', 'EshopModel', array('remember_states' => false))
->limitstart(0)
->limit($numberProducts)
->sort_options('rand()')
->getData();
Now the rand() option is not in the allowed set of options for sort so you also have to change the EShopModelProducts class to allow this as an option.
This is in components/com_eshop/models/products.php (note its products and not product)
So in the _buildQueryOrder method around line 215 add
'rand()' to the $allowedSortArr array.
As the sort order always adds the default of ASC to it then you also need to add the following if construct at around line 241
if ($sort == 'rand()')
$query->order($sort);
else
{
$query->order($sort . ' ' . $direct)
->order('a.ordering');
}
this replaces the code
$query->order($sort . ' ' . $direct)
->order('a.ordering');
This then gives a random selection of any product on the front page. If you want random featured items then you need to keep the ->product_featured(1) part of the query in the view.html.php
I have done some testing on the front page but not much around the rest of the site so I am hoping there is no knock on to other places, I dont think there should be.
Hope this helps someone.
components/com_eshop/views/frontpage/view.html.php
Change the call aat around line 76 to:
$products = RADModel::getInstance('Products', 'EshopModel', array('remember_states' => false))
->limitstart(0)
->limit($numberProducts)
->sort_options('rand()')
->getData();
Now the rand() option is not in the allowed set of options for sort so you also have to change the EShopModelProducts class to allow this as an option.
This is in components/com_eshop/models/products.php (note its products and not product)
So in the _buildQueryOrder method around line 215 add
'rand()' to the $allowedSortArr array.
As the sort order always adds the default of ASC to it then you also need to add the following if construct at around line 241
if ($sort == 'rand()')
$query->order($sort);
else
{
$query->order($sort . ' ' . $direct)
->order('a.ordering');
}
this replaces the code
$query->order($sort . ' ' . $direct)
->order('a.ordering');
This then gives a random selection of any product on the front page. If you want random featured items then you need to keep the ->product_featured(1) part of the query in the view.html.php
I have done some testing on the front page but not much around the rest of the site so I am hoping there is no knock on to other places, I dont think there should be.
Hope this helps someone.
Please Log in or Create an account to join the conversation.
Moderators: Tuan Pham Ngoc, Giang Dinh Truong, Dang Thuc Dam
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.