Skip to content

Actions#


In Miva Merchant development, Actions serve as directives that instruct Miva Merchant to execute specific tasks. These actions, identified by four-letter codes, control the platform’s behavior when triggered through URL parameters or hidden form inputs.

Actions automate key functionalities such as:

  • Adding/removing products from the cart.
  • Updating cart quantities.
  • Managing user authentication (login/logout).
  • Handling checkout processes.

By using actions, developers can integrate complex operations into their store efficiently without requiring extensive custom coding.


How Actions Work#

Actions in Miva Merchant are typically invoked in two ways:

  1. Form Submissions:

    • Actions can be embedded within <form> elements using hidden input fields.
    • When the form is submitted, Miva Merchant processes the specified action(s) and executes the corresponding functionality.
  2. URL Parameters:

    • Actions can be appended to URLs, allowing specific tasks to be triggered dynamically through links or redirects.
    • Example: Logging out a user by appending &Action=LOGO to a URL.

Most core actions are prebuilt into Miva Merchant, enabling developers to utilize existing functionality without creating custom forms or logic.


Chaining Multiple Actions#

Miva Merchant allows multiple actions to be chained together in a single form submission. This is commonly used in checkout processes, where multiple operations (e.g., order placement, shipping calculation, tax assessment, payment authorization) need to occur sequentially.

For example: - A checkout form might include hidden action codes for: - Placing the order (ORDR). - Calculating shipping (SHIP). - Applying taxes (TAXS). - Authorizing the transaction (AUTH).

This sequential execution ensures that all necessary steps are completed within a single submission.


Examples of Miva Actions#

Form Submission#

Forms containing hidden action inputs instruct Miva Merchant to perform specific operations when submitted.

Example: User Login Form#

<form method="post" action="https://yourstore.com/mm5/merchant.mvc">
    <input type="hidden" name="Action" value="LOGN">
    <input type="text" name="Customer_Login" placeholder="Email Address">
    <input type="password" name="Customer_Password" placeholder="Password">
    <button type="submit">Login</button>
</form>
- The LOGN action tells Miva Merchant to authenticate the user.

Example: Adding a Product to the Cart#

<form method="post" action="https://yourstore.com/mm5/merchant.mvc">
    <input type="hidden" name="Action" value="ADPR">
    <input type="hidden" name="Product_Code" value="PRODUCT123">
    <input type="number" name="Quantity" value="1">
    <button type="submit">Add to Cart</button>
</form>
- The ADPR action adds the specified product to the cart.


Using URL Parameters#

Actions can also be triggered dynamically via URL parameters, enabling seamless navigation and user interactions.

Example: Logging Out a User#

Appending &Action=LOGO to a URL instructs Miva to log out the user:

<a href="https://yourstore.com/mm5/merchant.mvc?Action=LOGO">Logout</a>
- When clicked, Miva Merchant logs the user out and redirects them accordingly.

Example: Directly Adding a Product to the Cart#

A product can be added to the cart using a direct URL:

<a href="https://yourstore.com/mm5/merchant.mvc?Action=ADPR&Product_Code=PRODUCT123&Quantity=1">
    Add to Cart
</a>
- This allows users to add items with a single click.


Understanding Action Execution#

The merchant.mvc controller in Miva Merchant is responsible for parsing and executing actions. When an action is submitted via a form or URL, Miva:

  1. Reads the action from the request.
  2. Maps the action to a predefined function.
  3. Executes the corresponding function.

This mapping is part of Miva’s core functionality and can be explored further in the Miva Merchant Limited Source Kit (LSK), which provides insights into how actions are processed internally.


Best Practices for Using Actions#

  1. Use Secure Form Submissions:

    • Ensure that forms handling sensitive data (e.g., login, checkout) use HTTPS to protect user information.
  2. Leverage URL-Based Actions for Navigation:

    • Actions in URLs can streamline user interactions, such as logging out or adding items to the cart.
  3. Chain Actions When Needed:

    • When multiple actions need to be performed in sequence (e.g., checkout steps), structure the form accordingly.
  4. Test Actions in a Staging Environment:

    • Before implementing actions on a live store, test them in a development branch to ensure they work as expected.

Summary#

Actions in Miva Merchant provide a streamlined way to automate essential store operations through form submissions and URL parameters. By leveraging Miva’s built-in actions, developers can efficiently manage cart operations, user authentication, and checkout processes without extensive custom scripting.