Understanding MivaScript Functions#
Defining and Using Merchant Functions#
Merchant functions let you package reusable logic into named routines. They follow the same tag syntax but introduce their own attributes.
Declaring a Function#
<MvFUNCTION NAME="MyFunction" PARAMETERS="var.input1, input2" STANDARDOUTPUTLEVEL="">
...function body...
</MvFUNCTION>
- NAME sets the function’s identifier.
- PARAMETERS lists comma‑separated inputs. Prefix with
var
to pass by reference. Inside the body, each parameter is available asl.parameterName
. - STANDARDOUTPUTLEVEL (optional) controls output visibility based on debug settings.
Returning Values#
Inside a function, compute intermediate values with <MvASSIGN>
, then use <MvFUNCTIONRETURN>
to send back your result:
<MvFUNCTION NAME="AddNumbers" PARAMETERS="a, b">
<MvASSIGN NAME="l.sum" VALUE="{ l.a + l.b }">
<MvFUNCTIONRETURN VALUE="{ l.sum }">
</MvFUNCTION>
Invoking Functions#
Once defined, call your function in several ways:
- Inline output via
<MvEVAL>
:
<MvEVAL EXPR="{ MyFunction(5, 3) }">
<MvIF>
or <MvWHILE>
:
<MvIF EXPR="{ IsUserVIP(customerId) }">…</MvIF>
<MvASSIGN>
:
<MvASSIGN NAME="l.result" VALUE="{ ComputeOrderValue(var.cart, 0.08) }">