We have a modified version of Levels so I'm not 100% sure if this is 'stock' or not. In any case the SFNT has a 'Featured Products' slider on the bottom of the page, that pulls products from the 'featured' category. I manually switch these around (when I remember) to keep it fresh. Right now it reads the products into an array and outputs using a default sort method. I was wondering if there is an easy-to-implement way to 'jumble' the array index, or otherwise randomize (or pseudo-randomize) the output products so the page slider would be 'fresh' without my manual intervention.
Announcement
Collapse
No announcement yet.
Randomize 'Featured Products' on SFNT
Collapse
X
-
To randomize the products, add this code above the FOREACH for the product list:
Code:<mvt:comment> This section will randomize the products generated by the ReadyTheme Product Listing being used. </mvt:comment> <mvt:foreach iterator="product" array="readytheme:products"> <mvt:assign name="g.random_item" value="random(miva_array_elements(l.settings:readytheme:products) - 1) + 1"/> <mvt:assign name="g.random_product" value="l.settings:product"/> <mvt:assign name="l.settings:product" value="l.settings:readytheme:products[g.random_item]"/> <mvt:assign name="g.item_counter" value="1"/> <mvt:foreach iterator="new_product" array="readytheme:products"> <mvt:if expr="g.item_counter EQ g.random_item"> <mvt:assign name="l.settings:new_product" value="g.random_product"/> <mvt:foreachstop/> </mvt:if> <mvt:assign name="g.item_counter" value="g.item_counter + 1"/> </mvt:foreach> </mvt:foreach>
Matt Zimmermann
Miva Web Developer
Alchemy Web Development
https://www.alchemywebdev.com
Site Development - Maintenance - Consultation
Miva Certified Developer
Miva Professional Developer
https://www.dev4web.net | Twitter
- 1 like
-
danceman If you are looking to change the amount of products, you can chance the display quantity in the ReadyTheme component. If you are looking to pull in random product, like the old Random function within Tool Kit, I'm not sure of a way to do that within this product list.Matt Zimmermann
Miva Web Developer
Alchemy Web Development
https://www.alchemywebdev.com
Site Development - Maintenance - Consultation
Miva Certified Developer
Miva Professional Developer
https://www.dev4web.net | Twitter
Comment
-
Thank you! I've been needing this for a while. It is much appreciated!Leslie Kirk
Miva Certified Developer
Miva Merchant Specialist since 1997
Previously of Webs Your Way (aka Leslie Nord leslienord)
Email me: [email protected]
www.lesliekirk.com
Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr
- 1 like
Comment
-
Originally posted by Matt Zimmermann View PostTo randomize the products, add this code above the FOREACH for the product list:
Code:<mvt:comment> This section will randomize the products generated by the ReadyTheme Product Listing being used. </mvt:comment> <mvt:foreach iterator="product" array="readytheme:products"> <mvt:assign name="g.random_item" value="random(miva_array_elements(l.settings:readytheme:products) - 1) + 1"/> <mvt:assign name="g.random_product" value="l.settings:product"/> <mvt:assign name="l.settings:product" value="l.settings:readytheme:products[g.random_item]"/> <mvt:assign name="g.item_counter" value="1"/> <mvt:foreach iterator="new_product" array="readytheme:products"> <mvt:if expr="g.item_counter EQ g.random_item"> <mvt:assign name="l.settings:new_product" value="g.random_product"/> <mvt:foreachstop/> </mvt:if> <mvt:assign name="g.item_counter" value="g.item_counter + 1"/> </mvt:foreach> </mvt:foreach>
Leslie Kirk
Miva Certified Developer
Miva Merchant Specialist since 1997
Previously of Webs Your Way (aka Leslie Nord leslienord)
Email me: [email protected]
www.lesliekirk.com
Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr
Comment
-
Looking here https://docs.miva.com/reference-guid...oduct-listings it seems as if Number of Products grabs the number you set then this script randomizes those. Try a higher number like 20 and you should see the randomizing at a guess. My not a real programmer concern is if you have 3000 products in 'all products' and it builds an array which it is going to sort and pick out 4 random every page load that might make the page chug.
In my case I created a category with 'featured products' which I update now and then. It pulls from those 20 to 30 products and randomizes those - in our case I'm trying to highlight some products which people tend to overlook.
Comment
-
Originally posted by habreu View PostLooking here https://docs.miva.com/reference-guid...oduct-listings it seems as if Number of Products grabs the number you set then this script randomizes those. Try a higher number like 20 and you should see the randomizing at a guess. My not a real programmer concern is if you have 3000 products in 'all products' and it builds an array which it is going to sort and pick out 4 random every page load that might make the page chug.
In my case I created a category with 'featured products' which I update now and then. It pulls from those 20 to 30 products and randomizes those - in our case I'm trying to highlight some products which people tend to overlook.Leslie Kirk
Miva Certified Developer
Miva Merchant Specialist since 1997
Previously of Webs Your Way (aka Leslie Nord leslienord)
Email me: [email protected]
www.lesliekirk.com
Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr
- 1 like
Comment
Comment