Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/c69da976081a67e5fa881a1f9cc196b8 to your computer and use it in GitHub Desktop.
Save steveosoule/c69da976081a67e5fa881a1f9cc196b8 to your computer and use it in GitHub Desktop.
Miva - INVC Fail Safe Read/Write Basket/Order Custom Fields
<mvt:comment>
Fail-safe Write
</mvt:comment>
<mvt:if expr="l.settings:page:code CIN 'INVC'">
<mvt:item name="customfields" param="Write_Basket( 'order_instructions', g.order_instructions )" />
<mvt:item name="customfields" param="Write_Order( l.settings:order:id, 'order_instructions', g.order_instructions )" />
</mvt:if>
<mvt:comment>
Fail-safe Read
</mvt:comment>
<mvt:item name="customfields" param="Read_Basket( 'order_instructions', l.settings:order_instructions )" />
<mvt:if expr="ISNULL l.settings:order_instructions">
<mvt:item name="customfields" param="Read_Order( l.settings:order:id, 'order_instructions', l.settings:order_instructions )" />
</mvt:if>

INVC Fail Safe Read/Write Basket/Order Custom Fields

This approach helps resolve timing issues where: at the time the template code evaluates it can sometimes still be a basket and sometimes have been converted from a basket to an order.

By reading-from & writing-to both, we account for both scenarios and have more reliable custom fields.

Fail-safe Write

Note: this assumes that g.order_instructions is always expected to be passed. If there are cases where it may not be passed from OPAY to INVC, then you may want to change the expression to l.settings:page:code CIN 'INVC' AND NOT ISNULL g.order_instructions

  • <mvt:if expr="l.settings:page:code CIN 'INVC'"> - Verifies that we're not viewing INVC from token list
  • Write_Basket() incase the basket has not been converted to an order
  • Write_Order() incase the basket has been converted to an order

Fail-safe Read

  • Read_Basket() first incase basket has not been converted to an order
  • If our value is null, then we can try again on the order
  • Read_Order() incase the basket has been converted to an order
  • Now l.settings:order_instructions should have the value if it was provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment