Originally posted by habreu
View Post
Announcement
Collapse
No announcement yet.
Randomize 'Featured Products' on SFNT
Collapse
X
-
- 1 like
-
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.
Leave a 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>
Leave a comment:
-
Thank you! I've been needing this for a while. It is much appreciated!
- 1 like
Leave a comment:
-
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.
Leave a comment:
-
Love this script - thanks Matt! Quick question - Is there a way to have it randomly grab random products and entirely switch out products as opposed to jumbling a set amount of images?
Leave a comment:
-
Thanks Matt. Works like a charm. You should add it to 'useful snippets' for the theme.
Leave a comment:
-
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>
- 1 like
Leave a comment:
-
Randomize 'Featured Products' on SFNT
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.Tags: None
Leave a comment: