Miva Merchant Development by Scot's Scripts

ORDERITEMS: Load OrderItemsDiscounts for Entire Order

Miva Knowledge Base
ORDERITEMS: Load OrderItemsDiscounts for Entire Order

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)

ORDERITEMS: Load OrderItemsDiscounts for Entire Order

Scot Ranney • August 12, 2026 (updated: August 12, 2026)


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.


This function does not exist in the LSK and is useful for loading all the order item discounts in one go without looping through each order item and loading individually.

<MvFUNCTION NAME = "OrderItemDiscountList_Load_Order_id" PARAMETERS = "order_id, orderitemdiscounts var" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = ""> 
	<MvOPENVIEW NAME = "Merchant" VIEW = "OrderItemDiscounts" 
		QUERY = "{ 'SELECT * FROM ' $ g.Store_Table_Prefix $ 'OrderItemDiscounts WHERE order_id = ? ORDER BY priority DESC, pgrp_id ASC' }" 
		FIELDS = "l.order_id"> 
 
	<MvIF EXPR = "{ g.MvOPENVIEW_Error }"> 
		<MvFUNCTIONRETURN VALUE = "{ [ g.Library_Filename_Utilities ].Error( 'MER-DBP-OID-00002', g.MvOPENVIEW_Error ) }"> 
	</MvIF> 
 
	<MvASSIGN NAME = "l.orderitemdiscount_count" VALUE = 0> 
	<MvWHILE EXPR = "{ NOT OrderItemDiscounts.d.EOF }"> 
		<MvEVAL EXPR = "{ OrderItemDiscount_Read( l.orderitemdiscounts[ ++l.orderitemdiscount_count ] ) }"> 
		<MvSKIP NAME = "Merchant" VIEW = "OrderItemDiscounts" ROWS = 1> 
	</MvWHILE> 
 
	<MvCLOSEVIEW NAME = "Merchant" VIEW = "OrderItemDiscounts"> 
	<MvFUNCTIONRETURN VALUE = "{ ListLoad_EOF_Return( 'MER-DBP-OID-00003', l.orderitemdiscount_count ) }"> 
</MvFUNCTION>

https://www.scotsscripts.com/mvblog/orderitems-load-orderitemsdiscounts-for-entire-order.html

mvkb_discount mvkb_mivascript