steveosoule
2/21/2017 - 11:31 PM

Miva - Shipment Picklist Reports | Total Product Revenue Reports | Aggregate Product Information

Miva - Shipment Picklist Reports | Total Product Revenue Reports | Aggregate Product Information

<mvt:comment>author: bedpauw</mvt:comment>

<mvt:foreach iterator="order" array="admin_order:orders">
	<mvt:foreach iterator="item" array="order:groups">
		<mvt:comment>Create array of all products</mvt:comment>
		<mvt:assign name="l.index" value="miva_array_insert_var( l.settings:all_products, l.settings:item, -1 )" />
	</mvt:foreach>
</mvt:foreach>
<mvt:comment>Duplicate array for comparison purposes</mvt:comment>
<mvt:assign name="l.settings:holderArray" value="l.settings:all_products"/>
<mvt:comment>Start index at position two as to not compare to itself in search</mvt:comment>
<mvt:assign name="l.currentIndex" value="2"/>
<mvt:foreach iterator="holderProduct" array="holderArray">
	<mvt:comment>Find the first instance after itself where the product ID is the same as current index of holderArray</mvt:comment>
	<mvt:assign name="l.removeIndex" value="miva_array_search( l.settings:all_products, l.currentIndex, l.settings:product, 'l.settings:product:product:id EQ l.settings:holderProduct:product:id' )"/>
	<mvt:comment>Run a while loop so we continue to run the search for all matches of the current index of holderArray</mvt:comment>
	<mvt:while expr="l.removeIndex NE 0">
		<mvt:assign name="l.grabQuantity" value="miva_variable_value('l.settings:all_products[' $ l.removeIndex $ ']:quantity')"/>
		<mvt:assign name="l.settings:holderProduct:quantity" value="l.settings:holderProduct:quantity + l.grabQuantity"/>
		<mvt:comment>Once the match is found and the quantity extracted, remove the matched index</mvt:comment>
		<mvt:assign name="l.remove" value="miva_array_delete( l.settings:all_products, l.removeIndex, 1 )"/>
		<mvt:assign name="l.remove2" value="miva_array_delete( l.settings:holderArray, l.removeIndex, 1 )"/>
		<mvt:comment>Check if there are more matches</mvt:comment>
		<mvt:assign name="l.removeIndex" value="miva_array_search( l.settings:all_products, l.currentIndex, l.settings:product, 'l.settings:product:product:id EQ l.settings:holderProduct:product:id' )"/>
		<mvt:comment>If no more matches, then increase currentIndex and move to the next new item</mvt:comment>
		<mvt:if expr="l.removeIndex EQ 0">
			<mvt:assign name="l.currentIndex" value="l.currentIndex + 1"/>
		</mvt:if>
	</mvt:while>
</mvt:foreach>
<mvt:comment>Dump array for testing</mvt:comment>
<mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:holderArray), ',', '<br>'))" />