Skip to content

Instantly share code, notes, and snippets.

@andrew-serrano
Created May 15, 2020 00:20
Show Gist options
  • Save andrew-serrano/dcffe1e647d3ff8083e9685443b5dd7f to your computer and use it in GitHub Desktop.
Save andrew-serrano/dcffe1e647d3ff8083e9685443b5dd7f to your computer and use it in GitHub Desktop.
Display product subscription discounts during runtime
<mvt:comment>
Defaults
</mvt:comment>
<mvt:comment>
The subscription id you would like to test to determine
if the product applies to a discount
</mvt:comment>
<mvt:assign name="l.subscription_term_id" value="4" />
<mvt:comment>
This will always default to 0 when returning the subscription discount
for master products
</mvt:comment>
<mvt:assign name="l.variant_id" value="0" />
<mvt:assign name="l.product_quantity" value="1" />
<mvt:comment>
Base Price
</mvt:comment>
<mvt:if expr="NOT ISNULL l.settings:product:base_price">
<mvt:assign name="l.product_price" value="l.settings:product:base_price" />
</mvt:if>
<mvt:comment>
Discount State
</mvt:comment>
<mvt:do file="g.Module_Feature_PGR_UT" name="l.DiscountState_CreateFromBasket" value="DiscountState_CreateFromBasket( g.Basket, l.discount_state )" />
<mvt:if expr="l.DiscountState_CreateFromBasket">
<mvt:do file="g.Module_Feature_PGR_UT" name="l.DiscountState_Load_PriceGroups_Basket" value="DiscountState_Load_PriceGroups_Basket(g.Basket, l.discount_state )" />
</mvt:if>
<mvt:if expr="l.DiscountState_Load_PriceGroups_Basket">
<mvt:do file="g.Module_Feature_PGR_UT" name="l.DiscountState_Disable_Unused_Item_PriceGroups" value="DiscountState_Disable_Unused_Item_PriceGroups( l.discount_state )" />
</mvt:if>
<mvt:if expr="l.DiscountState_Disable_Unused_Item_PriceGroups">
<mvt:do file="g.Module_Feature_PGR_UT" name="l.DiscountState_Predict_Baseline_Discounts" value="DiscountState_Predict_Baseline_Discounts( l.discount_state )" />
</mvt:if>
<mvt:comment>
Returns all of the product discounts that are applied
</mvt:comment>
<mvt:do file="g.Module_Feature_PGR_UT" name="l.DiscountState_Predict_Product_Discounts_WithProductSubscriptionTerm" value="DiscountState_Predict_Product_Discounts_WithProductSubscriptionTerm( l.discount_state , l.settings:product, l.subscription_term_id, l.variant_id, l.product_quantity, l.product_price, l.discounts, l.discounts_count)" />
<mvt:comment>
Append the `formatted_discount` member for
each discount
</mvt:comment>
<mvt:if expr="l.discounts_count">
<mvt:comment>
Update product price
</mvt:comment>
<mvt:do file="g.Module_Store_Module_Currency" name="l.settings:product:formatted_price" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.product_price )" />
<mvt:comment>
Copy values into the standard product discounts structure
</mvt:comment>
<mvt:assign name="l.settings:product:discounts" value="l.discounts" />
<mvt:comment>
Append `formatted_discount` member
</mvt:comment>
<mvt:foreach iterator="discount" array="product:discounts">
<mvt:do file="g.Module_Store_Module_Currency" name="l.settings:discount:formatted_discount" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:discount:discount )" />
</mvt:foreach>
</mvt:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment