Miva Merchant Development by Scot's Scripts

DISCOUNT: Get Discount State for Product or Product List

Miva Knowledge Base
DISCOUNT: Get Discount State for Product or Product List
Important Notice: This information is for internal reference only. Use at your own risk.
Does Google actually understand your Miva Merchant store? Our JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

DISCOUNT: Get Discount State for Product or Product List

Scot Ranney • March 19, 2026


Don't you hate when you can't get the discount price of a custom loaded product? Well, no more.

Load basic product records into an array and run it through the discount function. Works like a charm. The example below is from Red River CTGY where it shows prices for other sizes but the general idea is the same.

<mvt:if expr="NOT ISNULL l.settings:popular_sizes">
	<p><b>Shop Popular Sizes</b></p>
	<hr>
	<mvt:foreach iterator="item" array="popular_sizes">
		<mvt:do name="l.ok" file="g.Module_Library_DB" value="Runtime_Product_Load_Code_Cached( l.settings:item, l.settings:size_product)" />
		<mvt:if expr="l.settings:size_product:id GT 0">
			<mvt:assign name="l.ok" value="miva_array_insert(l.settings:size_products,l.settings:size_product,-1)" />
		</mvt:if>
	</mvt:foreach>
	<mvt:assign name="l.settings:product_count" value="miva_array_elements( l.settings:size_products )" />

	<mvt:do name="l.success" file="g.module_feature_tui_ut" value="CommonComponentFields_Initialize_Product_Discounts_Runtime( l.settings:size_products, l.settings:product_count )" />

	<mvt:foreach iterator="size_product" array="size_products">
		<mvt:do file="g.Module_Feature_URI_DB" name="l.success" value="URI_Load_product_Canonical(l.settings:size_product:id, l.settings:size_product:canonical)" />
		<div class="row mt-2 text-secondary">
			<div class="col-sm-9">
				<a class="link-secondary" href="&mvt:size_product:canonical:uri;">&mvt:size_product:name;</a>
			</div>
			<div class="col-sm-2 text-secondary text-monospace">
				<mvt:if expr="l.settings:size_product:discount_count GT 0">
					<span class="text-success">
						<mvt:eval expr="l.settings:size_product:formatted_price" />
					</span>
				<mvt:else>
					<mvt:eval expr="l.settings:size_product:formatted_price" />
				</mvt:if>
			</div>
			<div class="col-sm-1">
				<a title="add to cart" href="&mvte:urls:BASK:auto;?action=ADPR&product_code=&mvt:size_product:code;"><i class="fa-regular fa-cart-arrow-down"></i></a>
			</div>
		</div>
	</mvt:foreach>
</mvt:if>

Notes:

1. You need to get the product count and pass it into the discount function. Really weird because it could easily do that itself. Maybe a weird way to tell it to roll through the first 10 or whatever in case you're on a category page or other listing and don't need it to run through the entire list.


https://www.scotsscripts.com/mvblog/discount-get-discount-state-for-product-or-product-list.html

mvkb_discount mvkb_smt