Miva Merchant Development by Scot's Scripts

SORT: Build in API Sort Function (mivascript)

Miva Random Code Trivia

Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)
SEO Audit & Inquiries • News & Updates • SEO for Miva Merchant

SORT: Build in API Sort Function (mivascript)

THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.

Scot Ranney • December 19, 2023


Example: List all pages, sort by code.


  <div class="form-group">
	<label>Email Template</label>
	<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.module_feature_tui_db ].PageList_Load_All(l.pages) }" />
	<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.Module_Library_Utilities ].QuickSortArray(l.pages,':code',1) }" />
	<select name="_customerupload_notify_email_template" class="form-control col-3">
		<MvFOREACH ITERATOR = "l.page" INDEX = "l.pos" ARRAY = "l.pages">
				<MvIF EXPR = "{ l.page:id EQ g.customerupload_notify_email_template }">
					<option value="{ l.page:id }" selected><MvEVAL EXPR = "{ l.page:name $ ' (' $ l.page:code $ ')' }">
				<MvELSE>
					<option value="{ l.page:id }"><MvEVAL EXPR = "{ l.page:name $ ' (' $ l.page:code $ ')' }">
				</MvIF>
		</MvFOREACH>
	</select>
</div>

Create a unique sort field by rolling through the array initially and setting up a slugified sort field.

<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.module_feature_tui_db ].PageList_Load_All(l.pages) }" />

<MvFOREACH ITERATOR = "l.page" INDEX = "l.pos" ARRAY = "l.pages">
	<mvt:assign name="l._temp_array" value="l.page" />
	<mvt:assign name="l._temp_array:sort" value="slugify(substring(l.page:name,1,2) $ ' ' $ l.page:id $ ' ' $ l.page:code)" />
	<mvt:assign name="l.ok" value="miva_array_insert(l.settings:new_array,l._temp_array,-1)" />
</MvFOREACH>

//OK, this is smt code, got confused, but the idea is the same.

  <div class="form-group">
	<label>Email Template</label>

	<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.Module_Library_Utilities ].QuickSortArray(l.settings:new_array,':sort',1) }" />

	<select name="_customerupload_notify_email_template" class="form-control col-3">
		<MvFOREACH ITERATOR = "l.page" INDEX = "l.pos" ARRAY = "l.settings:new_array">
				<MvIF EXPR = "{ l.page:id EQ g.customerupload_notify_email_template }">
					<option value="{ l.page:id }" selected><MvEVAL EXPR = "{ l.page:name $ ' (' $ l.page:code $ ')' }">
				<MvELSE>
					<option value="{ l.page:id }"><MvEVAL EXPR = "{ l.page:name $ ' (' $ l.page:code $ ')' }">
				</MvIF>
		</MvFOREACH>
	</select>
</div>

https://www.scotsscripts.com/mvblog/sort-build-in-api-sort-function-mivascript.html

mivascript sort