| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Show random products from a category | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Re: Banner System Mod's HTML Banner
Would you please kindly guide how the script would look like to call products randomly from a specific category to display on a page?
Thank you in advance for your help.
__________________
X-Cart 5.3.3.4 Multivendor X-Cart 5.3.3.4 Business (Testing) |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Show random products from a category
You can extend your widget from \XLite\View\ItemsList\Product\Customer\Category\AC ategory class - this will allow you to show products from a particular category.
But the random order is not that easy. Yes, you can use "ORDER BY RAND()" by returning "RAND()" as the "order by" parameter in getSortByModeDefault() method. But MySQL is too slow when doing this on more than 100 products. So, you will have to implement some tricks to speed up random queries.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#3
|
|||||||||
|
|||||||||
Re: Show random products from a category
@sabinudash,
I have found an example of pulling random entities from a repo here: https://stackoverflow.com/a/39223980/1632233 I went ahead and tried to apply this to product repo and here is the implementation I came up with: Code:
Please, let me know if it works for you. Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker! Know how to make X-Cart better? Suggest an idea! |
|||||||||
|
#4
|
|||||||
|
|||||||
Re: Show random products from a category
Tony (once again - fantastic resources you always provide) So, I'm pretty new to x-cart. I'm learning as fast as I can... I'm clueless in how you go about applying this to the product repo...
__________________
X-Cart Business 5.3.5.4 make/model |
|||||||
|
|||
X-Cart forums © 2001-2020
|