html Miva - 变量批量定价和预测折扣

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Miva - 变量批量定价和预测折扣相关的知识,希望对你有一定的参考价值。

$(function(){
	var VairantVolumePricingMachine = {
		init: function(){
			if( !$('body').hasClass('PROD') ) return;
			console.log('hello from VairantVolumePricingMachine in main.js');
			MivaEvents.SubscribeToEvent('variant_changed', VairantVolumePricingMachine.processVariantChanged);
		},
		processVariantChanged: function(product_data){
			console.log('processVariantChanged');
			$.get('/mm5/merchant.mvc?Screen=api&get=Variant_Volume_Pricing', product_data, VairantVolumePricingMachine.processGET);
		},
		processGET: function(result, status, xhr){
			console.log('processGET');
			$('#js-variant-volume-pricing').html(result);
		}
	};

	VairantVolumePricingMachine.init();
});
<mvt:comment>
---------------------------------------------START TOOLKIT VARIANTARRAY REPLACEMENT (takes l.settings:product:id)---------------------------------------------
</mvt:comment>

<mvt:comment>
*****Load Attributes*****
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="AttributeList_Load_Product(l.settings:product:id, l.settings:product:attributes)" />
<mvt:if expr="l.settings:product:attributes[1]:attemp_id GT 0">
	<mvt:assign name="l.templateCode" value="l.settings:product:attributes[1]:code" />
	<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateAttrList_Load_Template(l.settings:product:attributes[1]:attemp_id, l.settings:product:attributes)" />
</mvt:if>
<mvt:foreach iterator="attribute" array="product:attributes">
	<mvt:comment>
	*****Load Options*****
	</mvt:comment>
	<mvt:if expr="l.settings:attribute:attemp_id GT 0">
		<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateOptionList_Load_Attribute(l.settings:attribute:id, l.settings:attribute:options)" />
	<mvt:else>
		<mvt:do file="g.Module_Library_DB" name="l.success" value="OptionList_Load_Attribute(l.settings:attribute:id, l.settings:attribute:options)" />
	</mvt:if>
	<mvt:foreach iterator="option" array="attribute:options">
		<mvt:comment>reset variable</mvt:comment>
		<mvt:assign name="l.settings:variant" value="NULL" />

		<mvt:comment>
		*****Load the Variant Parts && reset var*****
		</mvt:comment>
		<mvt:assign name="l.settings:productvariants" value="''" />
		<mvt:if expr="l.settings:attribute:attemp_id GT 0">
			<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductVariantList_Load_AttributeTemplateOption( l.settings:attribute:id, l.settings:option:id, l.settings:productvariants )" />
		<mvt:else>
			<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductVariantList_Load_Product_Option( l.settings:product:id, l.settings:attribute:id, l.settings:option:id, l.settings:productvariants )" />
		</mvt:if>
		<mvt:comment>for each variant part, do all of our stuff</mvt:comment>
		<mvt:foreach iterator="part" array="productvariants">
			<mvt:comment>
			*****Load the Variant Information*****
			</mvt:comment>
			<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Variant( l.settings:product:id, l.settings:part:variant_id, l.settings:variant )" />


			<mvt:comment>
			*****reformat variant for clarity's sake*****
			</mvt:comment>
			<mvt:assign name="l.settings:variant" value="l.settings:variant[1]" />

			<mvt:comment>
			*****init the runtime mvdo on the variant (this gives us formatted price, and sets us up for runtime discount mvdo should you choose to use it)*****
			</mvt:comment>
			<mvt:do file="g.module_feature_tui_ut" name="l.null" value="CommonComponentFields_Initialize_Product_Runtime( l.settings:variant )" />

			<mvt:comment>
			*****Drop the option that created this variant and the part_id in to it for later reference*****
			</mvt:comment>
			<mvt:assign name="l.settings:variant:option" value="l.settings:option" />
			<mvt:assign name="l.settings:variant:part_id" value="l.settings:part:variant_id" />

			<mvt:comment>
			*****The variant check loop looks at the product:variants array we're building, and sees if we've already made this variant or not to decide whether to build all the info out, or just append to the options (since this is run on an option basis, we only have 1 option at a time, and have to append them as we go)*****
			</mvt:comment>
			<mvt:assign name="g.exists" value="0" />
			<mvt:foreach iterator="variantCheck" array="product:variants">
				<mvt:if expr="l.settings:variant:code EQ l.settings:variantCheck:variant_code">

					<mvt:comment>THIS VARIANT HAS BEEN PUSHED BEFORE, FIND IT AND APPEND NEW OPTIONS</mvt:comment>
					<mvt:comment>l.tmp holds the variant_options info</mvt:comment>
					<mvt:if expr="l.settings:product:attributes[1]:attemp_id GT 0">
						<mvt:comment>attribute template detected, load in options and attributes based on that</mvt:comment>

						<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateOption_Load_ID(l.settings:variant:option:id, l.option)" />
						<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateAttr_Load_ID(l.settings:variant:option:attmpat_id, l.attr)" />

						<mvt:comment>l.tmp holds the variant_options info</mvt:comment>
						<mvt:assign name="l.tmp:attr_code" value="l.attr:code" />
						<mvt:assign name="l.tmp:attr_prompt" value="l.attr:prompt" />
						<mvt:assign name="l.tmp:opt_code" value="l.option:code" />
						<mvt:assign name="l.tmp:opt_prompt" value="l.option:prompt" />
						<mvt:assign name="l.tmp:template" value="l.templateCode" />

						<mvt:assign name="l.null" value="miva_array_insert_var( l.settings:variantCheck:variant_options, l.tmp, -1 )" />
						<mvt:assign name="l.settings:variantCheck:variant_options_raw" value="l.settings:variantCheck:variant_options_raw $ '+' $ l.tmp:attr_code $ ':' $ l.tmp:opt_code" />
					<mvt:else>
						<mvt:comment>no attribute template detected</mvt:comment>
						<mvt:comment>l.tmp holds the variant_options info</mvt:comment>
						<mvt:assign name="l.tmp" value="NULL" />
						<mvt:foreach iterator="loaded_attribute" array="product:attributes">
							<mvt:if expr="l.settings:loaded_attribute:id EQ l.settings:variant:option:attr_id">
								<mvt:assign name="l.tmp:attr_code" value="l.settings:loaded_attribute:code" />
								<mvt:assign name="l.tmp:attr_prompt" value="l.settings:loaded_attribute:prompt" />
								<mvt:assign name="l.tmp:opt_code" value="l.settings:variant:option:code" />
								<mvt:assign name="l.tmp:opt_prompt" value="l.settings:variant:option:prompt" />
							</mvt:if>
						</mvt:foreach>
						<mvt:assign name="l.null" value="miva_array_insert_var( l.settings:variantCheck:variant_options, l.tmp, -1 )" />
						<mvt:assign name="l.settings:variantCheck:variant_options_raw" value="l.settings:variantCheck:variant_options_raw $ '+' $ l.tmp:attr_code $ ':' $ l.tmp:opt_code" />
					</mvt:if>

					<mvt:comment>Here's our flag that tells us that we've seen this one before, so don't build out it's structure below</mvt:comment>
					<mvt:assign name="g.exists" value="1" />
				</mvt:if>
			</mvt:foreach>
			<mvt:if expr="g.exists NE 1">
				<mvt:comment>THIS VARIANT HASN'T BEEN PUSHED BEFORE, CREATE A NEW STRUCTURE</mvt:comment>
				<mvt:comment>BUILD STRUCTURE</mvt:comment>
				<mvt:assign name="l.settings:variantPush" value="NULL" />
				<mvt:assign name="l.settings:variantPush:product" value="l.settings:variant" />
				<mvt:assign name="l.settings:variantPush:product:option" value="''" />

				<mvt:if expr="l.settings:product:attributes[1]:attemp_id GT 0">
					<mvt:comment>attribute template detected, load in options and attributes based on that</mvt:comment>
					<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateOption_Load_ID(l.settings:variant:option:id, l.option)" />
					<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateAttr_Load_ID(l.option:attmpat_id, l.attr)" />

					<mvt:comment>l.tmp holds the variant_options info</mvt:comment>
					<mvt:assign name="l.tmp:attr_code" value="l.attr:code" />
					<mvt:assign name="l.tmp:attr_prompt" value="l.attr:prompt" />
					<mvt:assign name="l.tmp:opt_code" value="l.option:code" />
					<mvt:assign name="l.tmp:opt_prompt" value="l.option:prompt" />
					<mvt:assign name="l.tmp:template" value="l.templateCode" />

					<mvt:assign name="l.null" value="miva_array_insert_var( l.settings:variantCheck:variant_options, l.tmp, -1 )" />
					<mvt:assign name="l.settings:variantCheck:variant_options_raw" value="l.tmp:attr_code $ ':' $ l.tmp:opt_code" />
				<mvt:else>
					<mvt:comment>no attribute template detected</mvt:comment>
					<mvt:comment>l.tmp holds the variant_options info</mvt:comment>
					<mvt:assign name="l.tmp" value="NULL" />
					<mvt:foreach iterator="loaded_attribute" array="product:attributes">
						<mvt:if expr="l.settings:loaded_attribute:id EQ l.settings:variant:option:attr_id">
							<mvt:assign name="l.tmp:attr_code" value="l.settings:loaded_attribute:code" />
							<mvt:assign name="l.tmp:attr_prompt" value="l.settings:loaded_attribute:prompt" />
							<mvt:assign name="l.tmp:opt_code" value="l.settings:variant:option:code" />
							<mvt:assign name="l.tmp:opt_prompt" value="l.settings:variant:option:prompt" />
						</mvt:if>
					</mvt:foreach>
					<mvt:assign name="l.null" value="miva_array_insert_var( l.settings:variantPush:variant_options, l.tmp, -1 )" />
					<mvt:assign name="l.settings:variantPush:variant_options_raw" value="l.tmp:attr_code $ ':' $ l.tmp:opt_code" />
				</mvt:if>

				<mvt:comment>push to product:variants</mvt:comment>
				<mvt:assign name="l.array_length" value="miva_array_insert( l.settings:product:variants, l.settings:variantPush, -1 )" />
			</mvt:if>
		</mvt:foreach>
	</mvt:foreach>
</mvt:foreach>

<mvt:comment>
---------------------------------------------END TOOLKIT VARIANTARRAY REPLACEMENT---------------------------------------------
</mvt:comment>

<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_CreateFromBasket( g.Basket, l.discount_state )" />
<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Load_PriceGroups_Basket( g.Basket, l.discount_state )" />
<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Disable_Unused_Item_PriceGroups( l.discount_state )" />
<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Baseline_Discounts( l.discount_state )" />
<mvt:foreach iterator="variant" array="product:variants">

	<mvt:comment><!-- Load Variant Vol Pricing Table --></mvt:comment>
	<mvt:assign name="l.settings:variant_id" value="l.settings:variant:product:id" />
	<mvt:item name="volprice" param="variant_id" />
	<mvt:assign name="l.settings:variant:volprice" value="l.settings:volprice" />

	<mvt:assign name="l.variant_discount_state" value="l.discount_state" />
	<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Product_Discounts( l.variant_discount_state, l.settings:variant:product, '', 1, l.settings:variant:predicted_price, l.settings:variant:predicted_discounts, l.settings:variant:predicted_discount_count )" />
	<mvt:foreach iterator="volprice_row" array="variant:volprice:table">
		<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Product_Discounts( l.variant_discount_state, l.settings:variant:product, '', l.settings:volprice_row:low, l.settings:volprice_row:predicted_price, l.settings:volprice_row:predicted_discounts, l.settings:volprice_row:predicted_discount_count )" />
	</mvt:foreach>
</mvt:foreach>

<hr>

<mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:product), ',', '<br>'))" />
<mvt:if expr="g.get EQ 'Variant_Volume_Pricing' AND g.Product_Code AND g.Variant_ID">

	<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_CreateFromBasket( g.Basket, l.discount_state )" />
	<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Load_PriceGroups_Basket( g.Basket, l.discount_state )" />
	<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Disable_Unused_Item_PriceGroups( l.discount_state )" />
	<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Baseline_Discounts( l.discount_state )" />


	<mvt:do file="g.Module_Library_DB" name="l.settings:product:result_of:product_load" value="Runtime_Product_Load_Code(g.Product_Code, l.settings:product)" />
	<mvt:do file="g.Module_Library_DB" name="l.settings:product:result_of:productlist_load_part" value="ProductList_Load_Variant(l.settings:product:id, g.Variant_ID, l.settings:product:parts)" />

	<mvt:foreach iterator="part" array="product:parts">

		<mvt:comment><!-- Load Variant Vol Pricing Table --></mvt:comment>
		<mvt:assign name="l.settings:part_id" value="l.settings:part:id" />
		<mvt:item name="volprice" param="part_id" />
		<mvt:assign name="l.settings:part:volprice" value="l.settings:volprice" />


		<mvt:comment><mvt:do file="g.Module_Library_DB" name="l.settings:part::result_of:product_load" value="Runtime_Product_Load_ID(l.settings:part:id, l.settings:product)" /></mvt:comment>

		<mvt:assign name="l.part_discount_state" value="l.discount_state" />
		<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Product_Discounts( l.part_discount_state, l.settings:part, '', 1, l.settings:part:predicted_price, l.settings:part:predicted_discounts, l.settings:part:predicted_discount_count )" />
		<mvt:foreach iterator="volprice_row" array="part:volprice:table">
			<mvt:do file="g.Module_Feature_PGR_UT" name="l.result" value="DiscountState_Predict_Product_Discounts( l.part_discount_state, l.settings:part, '', l.settings:volprice_row:low, l.settings:volprice_row:predicted_price, l.settings:volprice_row:predicted_discounts, l.settings:volprice_row:predicted_discount_count )" />
		</mvt:foreach>
	</mvt:foreach>


	<table>
		<thead>
			<tr>
				<th>Range</th>
				<th>Amount</th>
			</tr>
		</thead>
		<mvt:foreach iterator="entry" array="part:volprice:table">
			<tr>
				<td>
					<mvt:if expr="l.settings:entry:low EQ l.settings:entry:high">
						&mvte:entry:low;
					<mvt:elseif expr="l.settings:entry:high">
						&mvte:entry:low;-&mvte:entry:high;
					<mvt:else>
						&mvte:entry:low;+
					</mvt:if>
				</td>
				<td>
					$&mvt:entry:predicted_price;
				</td>
			</tr>
		</mvt:foreach>
	</table>

	<mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:product), ',', '<br>'))" />

</mvt:if>

以上是关于html Miva - 变量批量定价和预测折扣的主要内容,如果未能解决你的问题,请参考以下文章

html 使用客户的实际Miva定价更新SearchSpring结果

xml Miva - 第三方数据集的运行时产品折扣

html Miva - 批量报告 - 饲料生成器

html Miva - 批量报告 - 获取客户登录

单价和折扣 - 事实或维度表

在Lazada销售产品的定价规则