Miva Merchant Development by Scot's Scripts

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

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

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)

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

Scot Ranney • May 20, 2024 (updated: July 01, 2024)


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.


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