Skip to content

mvt:do custom upcharge template#


Description#

This snippet demonstrates how to efficiently apply custom upcharges to a customer’s basket in an ecommerce platform using the mvt:do tag. By defining variables such as the charge amount, type, description, and tax status, you can dynamically insert custom charges like “Wire Transfer Fee” into the basket. The code ensures no double-charging by clearing previous charges of the same type before adding the new charge, then recalculates the basket’s total charges.

Snippet#

<mvt:comment>
|
|
|   Efficient mvt:do custom upcharges - function similar to toolkit upcharges
|       assign the 4 below variables and drop in anywhere above basket charge loop
|
|
</mvt:comment>

<mvt:assign name="l.customCharge:value"     value="28" />
<mvt:assign name="l.customCharge:type"      value="'CustomUpcharge'" />
<mvt:assign name="l.customCharge:descrip"   value="'Wire Transfer Fee'" />
<mvt:assign name="l.customCharge:taxExempt" value="0" />

<mvt:comment>
|
|   Clear all previous charges of type, prevents double charging
|
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="BasketCharge_Delete_All_Type( g.basket:basket_id, l.customCharge:type )" />

<mvt:comment>
|
|   Make the charge item
|
</mvt:comment>
<mvt:assign name="l.basketcharge:basket_id"     value="g.Basket:basket_id" />
<mvt:assign name="l.basketcharge:module_id"     value="0" />
<mvt:assign name="l.basketcharge:type"          value="l.customCharge:type" />
<mvt:assign name="l.basketcharge:descrip"       value="l.customCharge:descrip" />
<mvt:assign name="l.basketcharge:amount"        value="l.customCharge:value" />
<mvt:assign name="l.basketcharge:disp_amt"      value="l.customCharge:value" />
<mvt:assign name="l.basketcharge:tax_exempt"    value="l.customCharge:taxExempt" />

<mvt:comment>
|
|   Insert Charge
|
</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="BasketCharge_Insert( l.basketcharge )" />

<mvt:do file="g.Module_Library_DB" name="l.settings:basket:total" value="Basket_SubTotal( g.Basket:basket_id )" />

<mvt:assign name="l.settings:temp_charges"      value="''" />
<mvt:assign name="l.settings:basket:charges"    value="''" />

<mvt:do file="g.Module_Library_DB" name="l.success" value="BasketChargeList_Load_Basket( g.Basket:basket_id, l.settings:temp_charges )" />
<mvt:foreach iterator="charge" array="temp_charges">
    <mvt:if expr="( l.settings:charge:type EQ 'SHIPPING' ) AND ( NOT l.settings:basket:shipping )">
        <mvt:foreachcontinue />
    <mvt:elseif expr="(l.settings:charge:type EQ 'HANDLING' ) AND ( NOT l.settings:basket:handling )">
        <mvt:foreachcontinue />
    <mvt:elseif expr="(l.settings:charge:type EQ 'TAX' ) AND ( NOT l.settings:basket:salestax )">
        <mvt:foreachcontinue />
    <mvt:elseif expr="(l.settings:charge:type EQ 'DISCOUNT' ) AND ( NOT ISNULL l.settings:basket:discounts ) AND ( NOT l.settings:basket:discounts )">
        <mvt:foreachcontinue />
    </mvt:if>

    <mvt:do file="g.Module_Feature_TUI_UT" name="l.success" value="CommonComponentFields_Initialize_BasketCharge( l.settings:charge )" />
    <mvt:assign name="l.settings:basket:total"          value="l.settings:basket:total + ( l.settings:charge:amount ROUND 2 )" />
    <mvt:assign name="l.settings:basket:charges_count"  value="miva_array_insert_var( l.settings:basket:charges, l.settings:charge, -1 )" />
</mvt:foreach>

<mvt:do file="g.Module_Store_Module_Currency" name="l.settings:basket:formatted_total" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:basket:total )" />