Custom Fields Functions#
The Custom Field Function Syntax in Miva Merchant provides developers with a robust set of tools to interact with custom fields seamlessly. These functions enable users to read and write data to custom fields associated with various entities such as pages, products, categories, customers, baskets, and orders. Below is an exhaustive breakdown of the Custom Field Function Syntax:
Syntax#
- All functions follow a consistent structure:
[Read/Write]_[Entity]_Code
or[Read/Write]_[Entity]_ID
. - Parameters include the entity code/ID (e.g., product, category), the custom field code, and a variable for storing the retrieved data or the data to be stored depending on the function used.
- When reading a custom field, the retrieved data is automatically stored in
l.settings:custom_fields
if no variable is specified.
Reading Functions#
- Read_Product_Code/Read_Product_ID: Reads the value of a custom field associated with a product.
- Read_Category_Code/Read_Category_ID: Reads the value of a custom field associated with a category.
- Read_Customer_Code/Read_Customer_ID: Reads the value of a custom field associated with a customer.
- Read_Basket: Reads the value of a custom field associated with a basket.
- Read_Order: Reads the value of a custom field associated with an order.
- Read_Page_Code/Read_Page_ID: Reads the value of a custom field associated with an page.
Writing Functions#
- Write_Product_Code/Write_Product_ID: Writes a value to a custom field associated with a product.
- Write_Category_Code/Write_Category_ID: Writes a value to a custom field associated with a category.
- Write_Customer_Code/Write_Customer_ID: Writes a value to a custom field associated with a customer.
- Write_Basket: Writes a value to a custom field associated with a basket.
- Write_Order: Writes a value to a custom field associated with an order.
- Write_Page_Code/Write_Page_ID: Writes a value to a custom field associated with an order.
Debugging#
- Debug_Custom_Field: Provides debugging support for troubleshooting custom field-related issues.
Note
The customfields
item must be assigned to the template in order to use the following functions.
- Reading functions:
<mvt:item name="customfields" param="Read_Category_Code( 'category_code', 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Category_ID( l.settings:category:id, 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Customer_Login( 'test@test.com', 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Customer_ID( l.settings:customer:id, 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Order( l.settings:order:id, 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Basket( 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Product_Code( 'product_code', 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Product_ID( l.settings:product:id, 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Read_Page_Code( 'page_code', 'custom_field_code', l.settings:customfields )" />
- Writing functions:
<mvt:item name="customfields" param="Write_Category_Code( 'category_code', 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Category_ID( l.settings:category:id, 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Customer_Login( 'test@test.com', 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Customer_ID( l.settings:customer:id, 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Order( 1000, 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Basket( 'custom_field_code', l.settings:customfields )" /> <mvt:item name="customfields" param="Write_Product_Code( 'product_code', 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Product_ID( .settings:product:id, 'custom_field_code', 'value' )" /> <mvt:item name="customfields" param="Write_Page_Code( 'page_code', 'custom_field_code', 'value' )" />
Template Use#
When using a list layout or order contents layout template within Miva a Custom Fields setting is available. When a custom field is assigned to the template than it will be available within the l.settings
structure for the template. For example if the custom field code brand
is assigned to the Product Display Layout template then it will be available using l.settings:product:customfield_values:customfields:brand
variable.