Skip to content

Debugging Custom Fields#


Debugging custom fields in Miva Merchant is essential for ensuring that your data flows seamlessly across templates, custom workflows, and integrations. Whether troubleshooting why a field isn’t displaying as expected or diagnosing API issues, Miva provides powerful tools and best practices to identify and resolve problems effectively.


Tools for Debugging Custom Fields#

Tokenlist#

The Tokenlist module provides a comprehensive view of all variables available on a page, including custom fields. Use it to:

  • Verify that custom fields are loaded correctly.
  • Inspect their values and data types.
  • Confirm their availability in specific contexts.

Steps to Use Tokenlist:

  1. Assign the Tokenlist module to the page you’re debugging.
  2. Access the Tokenlist modal from the More menu on the page.
  3. Search for the desired custom field under the customfield_values structure.

Debug() Function#

The Debug() function is a powerful tool for troubleshooting custom field issues directly in templates. It outputs error messages, variable values, and debug information in the admin interface.

Usage:

<mvt:item name="customfields" param="Debug()" />

Example: Conditional Debugging:

<mvt:if expr="s.remote_addr EQ '123.456.789.0'">
    <mvt:item name="customfields" param="Debug()" />
</mvt:if>

This ensures that debugging output is only visible when accessed from a specific IP address, reducing the risk of exposing debug information on live sites.


JSON API Debugging#

Use the Miva JSON API to validate that custom fields are accessible programmatically. Ensure the Public checkbox is enabled for any custom field you wish to query via the API.


Common Debugging Scenarios#

Custom Field Not Displaying in Templates#

Problem:#

A custom field doesn’t display in the template even though it’s assigned to the correct entity.

Solution:#

  1. Verify Field Availability:
    • Use Tokenlist to confirm the custom field is available in the current template context.
  2. Check Field Assignment:
    • Ensure the custom field is correctly assigned to the relevant entity (e.g., product, order).
  3. Verify Syntax:
    • Ensure the field code is referenced correctly in the template:
      &mvt:product:customfield_values:customfields:field_code;
      

Data Not Transferring from Basket to Order#

Problem:#

Basket custom field data isn’t transferring to the corresponding order custom field.

Solution:#

  1. Check Matching Codes:
    • Verify that the field codes for the basket and order custom fields match exactly (e.g., basket_notes and order_notes).
  2. Confirm Write Operation:
    • Ensure the data is being written to the basket custom field:
      <mvt:item name="customfields" param="Write_Basket( 'basket_notes', g.notes )" />
      
  3. Test Checkout Process:
    • Place a test order and confirm the data appears in the order custom field via Tokenlist or the admin interface.

Custom Field Not Accessible via JSON API#

Problem:#

A custom field isn’t appearing in the JSON API response.

Solution:#

  1. Enable Public Access:
    • Ensure the Public checkbox is enabled for the custom field in the admin interface.
  2. Include the customfields Parameter:
    • Add CustomField_Values:* within the filter object to your API request.
  3. Validate Field in API Response:
    • Use Postman or curl to test the API request and verify the field is included.

Best Practices for Debugging#

  1. Use a Controlled Environment:
    • Debug in a branch or sandbox environment to avoid impacting live customers.
  2. Document Debugging Steps:
    • Keep track of the changes made and their outcomes for future reference.
  3. Test Incrementally:
    • Make small changes and test each step to isolate issues effectively.
  4. Validate User Input:
    • Ensure that data entered into custom fields meets expected formats and constraints.
  5. Utilize Logging:
    • Use Miva’s logging features or external logging tools to track data flow and identify anomalies.

Summary#

Debugging custom fields in Miva Merchant is a systematic process that involves leveraging tools like Tokenlist, the Debug() function, and the JSON API. By understanding common issues and following best practices, you can identify and resolve problems efficiently, ensuring your store operates smoothly.