Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/c84a99ea4dcb4cefbe413e201224a133 to your computer and use it in GitHub Desktop.
Save steveosoule/c84a99ea4dcb4cefbe413e201224a133 to your computer and use it in GitHub Desktop.
Miva - Sort & Update Attribute-Option Display Order
<mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code( g.Product_Code, l.settings:product )" />
<mvt:do file="g.Module_Library_DB" name="l.success" value="AttributeList_Load_Product( l.settings:product:id, l.settings:product:attributes )" />
<mvt:foreach iterator="attribute" array="product:attributes">
<mvt:do file="g.Module_Library_DB" name="l.success" value="OptionList_Load_Attribute( l.settings:attribute:id, l.settings:attribute:options )" />
<mvt:comment>
Only Sort Length Attributes
</mvt:comment>
<mvt:if expr="l.settings:attribute:code NE 'length'">
<mvt:foreachcontinue />
</mvt:if>
<mvt:comment>
Assign the :original_offset from the POS
</mvt:comment>
<mvt:foreach iterator="option" array="attribute:options">
<mvt:assign name="l.settings:option:option_change:id" value="l.settings:option:id" />
<mvt:assign name="l.settings:option:option_change:original_offset" value="l.pos2" />
</mvt:foreach>
<mvt:comment>
Sort the Options
</mvt:comment>
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="QuickSortArray( l.settings:attribute:options, ':prompt', 1 )" />
<mvt:comment>
Assign the new :offset
</mvt:comment>
<mvt:foreach iterator="option" array="attribute:options">
<mvt:assign name="l.settings:option:option_change:offset" value="l.pos2" />
<mvt:assign name="l.result" value="miva_array_insert( l.settings:attribute:option_changes, l.settings:option:option_change, -1 )" />
</mvt:foreach>
<mvt:comment>
Update the Offsets/Display Order
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.settings:attribute:ProductAttributeOptionList_Update_Offsets_Result" value="ProductAttributeOptionList_Update_Offsets(l.settings:product:id, l.settings:attribute:id, l.settings:attribute:option_changes)" />
</mvt:foreach>
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.settings:product )" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment