Miva Merchant Modules and Development
Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

PRODUCT PRICES: Set Discounts in SMT Code for Random Groups of Products

Scot Ranney • May 20, 2024


Loading products using runtime and other functions will give you product info but will not give you pricegroup adjustments. The code below will.

<mvt:comment>
#
# load some products
#
</mvt:comment>
<mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_Code( 'backpacks', l.settings:current_category )" />

<mvt:do name="l.result" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:current_category:id, g.Offset, 100, g.NextOffset, l.settings:products )" />

<mvt:comment>
#
# Pass array of products into pricegroups function. 
# Price and formatted_price get replaced in products structure with the predicted discounted price. 
#
# Works on product level discounts only.
#
</mvt:comment>

<mvt:assign name="g.product_count" value="miva_array_elements( l.settings:products )" />

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

<mvt:foreach iterator="product" array="products">
	<div>Product Code: &mvt:product:code;</div>
	<div>Discount Count: &mvt:product:discount_count;</div>
	<div>Formatted Price: &mvt:product:formatted_price;</div>

	<mvt:foreach iterator="discount" array="product:discounts">
	   <div>Description:&mvt:discount:descrip;</div>
	   <div>Discount: &mvt:discount:discount;</div>
	   <div>Formatted Discount: &mvt:discount:formatted_discount;</div>
	</mvt:foreach>
</mvt:foreach>

https://www.scotsscripts.com/mvblog/product-prices-set-discounts-in-smt-code-for-random-groups-of-products.html

mvkb_price mvkb_pricegroups mvkb_smt