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:
- Assign the Tokenlist module to the page you’re debugging.
- Access the Tokenlist modal from the More menu on the page.
- 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:#
- Verify Field Availability:
- Use Tokenlist to confirm the custom field is available in the current template context.
- Check Field Assignment:
- Ensure the custom field is correctly assigned to the relevant entity (e.g., product, order).
- Verify Syntax:
- Ensure the field code is referenced correctly in the template:
&mvt:product:customfield_values:customfields:field_code;
- Ensure the field code is referenced correctly in the template:
Data Not Transferring from Basket to Order#
Problem:#
Basket custom field data isn’t transferring to the corresponding order custom field.
Solution:#
- Check Matching Codes:
- Verify that the field codes for the basket and order custom fields match exactly (e.g.,
basket_notes
andorder_notes
).
- Verify that the field codes for the basket and order custom fields match exactly (e.g.,
- 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 )" />
- Ensure the data is being written to the basket custom field:
- 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:#
- Enable Public Access:
- Ensure the
Public
checkbox is enabled for the custom field in the admin interface.
- Ensure the
- Include the
customfields
Parameter:- Add
CustomField_Values:*
within the filter object to your API request.
- Add
- Validate Field in API Response:
- Use Postman or curl to test the API request and verify the field is included.
Best Practices for Debugging#
- Use a Controlled Environment:
- Debug in a branch or sandbox environment to avoid impacting live customers.
- Document Debugging Steps:
- Keep track of the changes made and their outcomes for future reference.
- Test Incrementally:
- Make small changes and test each step to isolate issues effectively.
- Validate User Input:
- Ensure that data entered into custom fields meets expected formats and constraints.
- 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.