Skip to content

Instantly share code, notes, and snippets.

@ghassani
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghassani/21be935b8b8426296014 to your computer and use it in GitHub Desktop.
Save ghassani/21be935b8b8426296014 to your computer and use it in GitHub Desktop.
Predict Variant Discounts With Toolbelt variantarray function
<mvt:assign name="l.settings:test_products2" value="''" />
<mvt:foreach iterator="product" array="registry:products">
<mvt:assign name="l.settings:product:id" value="l.settings:product:product_id" />
<mvt:assign name="l.settings:product_count" value="miva_array_insert(l.settings:test_products2, l.settings:product, -1)" />
</mvt:foreach>
<mvt:item name="ry_toolbelt" param="do|g.Module_Feature_TUI_UT|g.state_result|CommonComponentFields_Initialize_Product_Discounts_Runtime(l.all_settings:test_products2, 2)" />
<mvt:eval expr="glosub(miva_array_serialize(l.settings:test_products2), ',', '<br />')" />
<hr /><hr /><hr /><hr />
<mct:comment>Load the discount state. This may be cached somewhere, so if we can find out where we can check to see if it is cached first and if not execute the next 3 functions</mvt:comment>
<mvt:item name="ry_toolbelt" param="do|g.Module_Feature_PGR_UT|g.state_result|DiscountState_CreateFromBasket(g.basket, l.all_settings:discount_state)" />
<mvt:item name="ry_toolbelt" param="do|g.Module_Feature_PGR_UT|g.state_result|DiscountState_Load_PriceGroups_Basket(g.basket, l.all_settings:discount_state)" />
<mvt:item name="ry_toolbelt" param="do|g.Module_Feature_PGR_UT|g.state_result|DiscountState_Predict_Baseline_Discounts(l.all_settings:discount_state)" />
<mct:comment>Load the variant array for the master product</mvt:comment>
<mvt:item name="toolkit" param="variantarray|vcount|l.all_settings:product:code" />
<mvt:if expr="g.vcount GT 0">
<mvt:foreach iterator="variant" array="variants">
<mct:comment>Copy the master product and update its base pricing with the variant products price</mvt:comment>
<mvt:assign name="l.settings:product_test" value="l.settings:product" />
<mvt:assign name="l.settings:product_test:base_price" value="l.settings:variant:price" />
<mvt:assign name="l.settings:product_test:variant_code" value="l.settings:variant:variant_code" />
<mvt:assign name="l.settings:product_test:formatted_base_price" value="l.settings:variant:formatted_price" />
<mvt:assign name="l.settings:product_test:price" value="l.settings:variant:price" />
<mvt:assign name="l.settings:product_test:formatted_price" value="l.settings:variant:formatted_price" />
<mvt:assign name="l.settings:product_test:retail_price" value="l.settings:variant:price" />
<mvt:assign name="l.settings:product_test:formatted_retail_price" value="l.settings:variant:formatted_price" />
<mct:comment>Predict the discounts by executing this function</mvt:comment>
<mvt:item name="ry_toolbelt" param="do|g.Module_Feature_PGR_UT|g.state_result|DiscountState_Predict_Product_Discounts(l.all_settings:discount_state, l.all_settings:product_test, l.all_settings:variant:variant_id, 1, l.all_settings:product_test:price, l.all_settings:product_test:discounts, l.all_settings:product_test:discount_count)" />
<mct:comment>
Discounted Price: l.settings:product_test:price
Base Price: l.settings:product_test:base_price
Discounts: l.settings:product_test:discounts - An array of processed discounts
Discount Count: l.settings:product_test:discount_count - The count of discounts applied
</mvt:comment>
</mvt:foreach>
</mvt:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment