Skip to content

Instantly share code, notes, and snippets.

@andrew-serrano
Last active November 21, 2019 22:05
Show Gist options
  • Save andrew-serrano/85b53542e37ba7b38fa1200e764a317f to your computer and use it in GitHub Desktop.
Save andrew-serrano/85b53542e37ba7b38fa1200e764a317f to your computer and use it in GitHub Desktop.
Will return the lowest variant part
<mvt:item name="all_products" />
<mvt:comment>
Products
</mvt:comment>
<mvt:foreach iterator="product" array="all_products:products">
<mvt:comment>
NULL
</mvt:comment>
<mvt:assign name="l.product_as_low_as_prices" value="''" />
<mvt:assign name="l.product_as_low_as_price" value="''" />
<mvt:comment>
Load all variants
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.ProductVariantList_Load_Product_Count" value="ProductVariantList_Load_Product(l.settings:product:id , l.settings:product:temp_variants)" />
<mvt:if expr="l.ProductVariantList_Load_Product_Count EQ 0">
<mvt:foreachcontinue/>
</mvt:if>
<mvt:comment>
Iterate over parts
</mvt:comment>
<mvt:foreach iterator="temp_variant" array="product:temp_variants">
<mvt:comment>
Default
</mvt:comment>
<mvt:assign name="l.temp_as_low_as_price_structure:price" value="0" />
<mvt:assign name="l.productvariantpricing" value="''" />
<mvt:comment>
Determine the price method
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductVariantPricing_Load_Variant(l.settings:temp_variant:product_id, l.settings:temp_variant:variant_id, l.productvariantpricing)" />
<mvt:comment>
Method:
0 - Controlled By Master
1 - Specific Values
2 - Sum of Parts
</mvt:comment>
<mvt:if expr="l.productvariantpricing:method EQ 0">
<mvt:comment>
Use Master Price
</mvt:comment>
<mvt:assign name="l.temp_as_low_as_price_structure:price" value="l.settings:product:price" />
<mvt:elseif expr="l.productvariantpricing:method EQ 1">
<mvt:comment>
Return specific price value
</mvt:comment>
<mvt:assign name="l.temp_as_low_as_price_structure:price" value="l.productvariantpricing:price" />
<mvt:else>
<mvt:comment>
Sum of Parts
</mvt:comment>
<mvt:foreach iterator="part" array="temp_variant:parts">
<mvt:comment>
Load quantity
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductVariantPartList_Load_Variant(l.settings:product:id,l.settings:temp_variant:variant_id, l.settings:product:temp_variants)" />
<mvt:comment>
Return price
</mvt:comment>
<mvt:assign name="l.temp_as_low_as_price_structure:price" value="l.temp_as_low_as_price_structure:price + (l.settings:part:price * l.settings:product:temp_variants[l.pos3]:quantity)" />
</mvt:foreach>
</mvt:if>
<mvt:comment>
Insert temp structure
</mvt:comment>
<mvt:assign name="l.product_as_low_as_prices_count" value="miva_array_insert( l.product_as_low_as_prices, l.temp_as_low_as_price_structure, -1 )" />
</mvt:foreach>
<mvt:if expr="l.product_as_low_as_prices_count EQ 0">
<mvt:foreachcontinue/>
</mvt:if>
<mvt:comment>
Sort by price
</mvt:comment>
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="QuickSortArray(l.product_as_low_as_prices, ':price' , 1)" />
<mvt:comment>
Return first option
E.G. l.product_as_low_as_price:price
</mvt:comment>
<mvt:assign name="l.product_as_low_as_price" value="miva_array_shift(l.product_as_low_as_prices)" />
Master Product Code: &mvt:product:code;<br/>
Price: <mvt:eval expr="l.product_as_low_as_price:price" /><br/>
<hr/>
</mvt:foreach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment