Understanding MivaScript#
Before delving into the Miva Merchant API, it’s essential to grasp the foundation of the language it operates on, MivaScript. This language serves as the backbone for developing custom modules and applications within the Miva Merchant platform. Let’s explore the key aspects of MivaScript:
Introduction to MivaScript#
-
Analogous to Other Languages:
- Just as developers need to understand Objective-C for iPhone app development or Ruby for Ruby on Rails, familiarity with MivaScript is crucial for working within the Miva Merchant ecosystem.
-
MivaScript’s History:
- MivaScript has been in existence since the mid-90s and is maintained by MivaMerchant.
- MivaScript.com serves as an invaluable resource for beginners, offering insights into the language’s background and available functions.
Components of MivaScript#
-
Functions:
- MivaScript includes numerous built-in functions essential for various programming tasks.
- Functions like “length” provide functionality for common operations, enhancing the language’s versatility and efficiency.
-
Tags:
- Tags play a pivotal role in MivaScript, resembling HTML or XML elements.
- Key tags like MVAssign and MVEval facilitate variable assignment and evaluation, respectively, contributing to dynamic scripting capabilities.
Exploring Tags and Functions#
-
Understanding MVAssign and MVEval:
- MVAssign creates variables, while MVEval evaluates expressions and outputs results.
- Tags follow a specific syntax convention, with attributes tailored to each tag’s functionality.
-
Working with Built-in Functions:
- Functions like “substring” offer powerful string manipulation capabilities within MivaScript.
- These functions are integrated into tags, enabling developers to perform complex operations seamlessly.
Compilation and Execution#
-
Compilation Process:
- MivaScript files need to be compiled before execution, ensuring proper integration with the Miva Merchant engine.
- Developers can use tools like the MivaScript compiler to compile their scripts efficiently.
-
Execution on Web Servers:
- Compiled MivaScript files can be deployed on web servers equipped with the Miva Merchant engine for execution.
- Testing and debugging scripts can be done in a development environment before deploying to production servers.
Understanding the Syntax of MivaScript Functions#
In MivaScript, defining and utilizing functions is essential for modular and efficient coding within the Miva Merchant environment. Let’s dissect the syntax and functionality of creating and invoking merchant functions:
Syntax of Defining a New Merchant Function#
-
Using the
<MvFUNCTION>
Tag:- To define a new function, developers utilize the
<MvFUNCTION>
tag, specifying attributes like name and parameters.
- To define a new function, developers utilize the
-
Parameter Passing:
- Parameters are listed as a comma-separated list within the “parameters” attribute.
<MvFUNCTION NAME = "Module_Description" PARAMETERS = "module var, order" STANDARDOUTPUTLEVEL = ""> <MvASSIGN NAME = "l.module:code" VALUE = "ex-system"> <MvASSIGN NAME = "l.module:name" VALUE = "System Extensions Example"> <MvASSIGN NAME = "l.module:provider" VALUE = "Miva Merchant"> <MvASSIGN NAME = "l.module:version" VALUE = "5.5000"> <MvASSIGN NAME = "l.module:api_ver" VALUE = "5.00"> <MvASSIGN NAME = "l.module:features" VALUE = "system, vis_system"> </MvFUNCTION>
- Parameters prefixed with “var” denote pass-by-reference, whereas plain parameters imply pass-by-value.
-
Local Variable Scope:
- All parameters passed into a function automatically become local variables within that function’s scope.
-
Accessing Parameters:
- Within the function, parameters can be accessed directly without prefixing with “l.”.
Example: Creating and Using a Custom Function#
-
Defining a Function:
- A custom function, such as “my function,” is created using the
<MvFUNCTION>
tag. - Parameters can be left empty if the function doesn’t require any inputs.
- A custom function, such as “my function,” is created using the
-
Attributes and Output Level:
- Additional attributes like “standard output level” can be specified to control function output behavior.
-
Implementing Function Logic:
- Within the function, code logic can be executed, such as mathematical calculations or data manipulation.
-
Returning Values:
- Functions can return values either through explicit output using
<MvEval>
or by using the “mv function return” tag.
- Functions can return values either through explicit output using
<MvFUNCTION NAME = "MyFunction" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.sum" VALUE = "{ 10 + 10 - 5 }">
<MvFUNCTIONRETURN VALUE = "{ l.sum }">
</MvFUNCTION>
<MvASSIGN NAME = "l.my_sum" VALUE = "{ MyFunction() }">
<MvEVAL EXPR = "{ 'The Sum is ' $ l.mysum }">
Calling a Custom Function#
-
Invocation Methods:
- Custom functions can be called using various methods, including
<MvEval>
or within conditional statements like “if” or “while” loops.
- Custom functions can be called using various methods, including
-
Passing Parameters:
- Parameters, if required, are passed during function invocation either as literals or variable references.
-
Outputting Results:
- Results from the function can be outputted directly to the page using
<MvEval>
or stored in variables for further processing.
- Results from the function can be outputted directly to the page using
Compilation and Execution#
-
Compilation Process:
- MivaScript files containing functions need to be compiled before deployment onto Miva Merchant servers.