I want to share a thought and see if this would be a good candidate for a built-in Miva function. Quick backstory: On product pages, my Related Products are displayed in a slider, so although all of them are always on the page, not all of them are seen unless the user scrolls through the list. As such, I wanted to randomize the list to give each item equal exposure. I didn't find a built-in sorting method to randomize an array, so I explored ways to create this manually.
A quick Google search shows that there is a very established algorithm for random sorting called the Fisher–Yates shuffle. I found a website that shows it implemented in basically every programming language under the sun (except Mivascript, of course), which helped me figure out how it actually works and adapt it to Miva SMT code for my PROD page.
I only need this in one place so far, so I didn't both with a module. However, I know that Miva has a few built-in sorting functions already, and I thought something like this would be a good candidate for inclusion in a future release. Random sorting is pretty handy, and I haven't found anything in Miva so far to accomplish this.
What do you think? Is this something that would be useful enough to include in the engine or even a function in Merchant? Is there anything built in that I've overlooked to accomplish similar results?
Josh
A quick Google search shows that there is a very established algorithm for random sorting called the Fisher–Yates shuffle. I found a website that shows it implemented in basically every programming language under the sun (except Mivascript, of course), which helped me figure out how it actually works and adapt it to Miva SMT code for my PROD page.
Code:
<mvt:assign name="g.i" value="miva_array_elements(l.settings:related_products:products)"/> <mvt:while expr="g.i GT 0"> <mvt:assign name="g.random" value="random(g.i - 1)"/> <mvt:assign name="g.random" value="g.random + 1"/> <mvt:assign name="g.null" value="miva_array_copy(l.settings:related_products:products,g.i,1,g.temparray,1)"/> <mvt:assign name="g.null" value="miva_array_copy(l.settings:related_products:products,g.random,1,l.settings:related_products:products, g.i)"/> <mvt:assign name="g.null" value="miva_array_copy(g.temparray,1,1,l.settings:related_products:products,g.random)"/> <mvt:assign name="g.i" value="g.i - 1"/> </mvt:while>
What do you think? Is this something that would be useful enough to include in the engine or even a function in Merchant? Is there anything built in that I've overlooked to accomplish similar results?
Josh
Comment