<mvt:comment>
| ------------------------------------------------
| Variant Basket Item Replacement (VBIR) with fix for Skipped Replacements
| ------------------------------------------------
| This custom functionality replicates the VBIR module,
| The main difference is that the standard VBIR module ties into the ADPR, ADPM, actions and sometimes products item don't get updated.
| This code will always ensure that the basket item codes are updated.
</mvt:comment>
<mvt:foreach iterator="item" array="basket:items">
<mvt:comment>
| We only need to do this process for items with a single variant part
</mvt:comment>
<mvt:if expr="miva_array_elements( l.settings:item:parts ) NE 1 ">
<mvt:foreachcontinue/>
</mvt:if>
<mvt:comment>
| Update the DB with our custom variant code logic
</mvt:comment>
<mvt:if expr="l.settings:item:parts[1]:code NE l.settings:item:code">
<mvt:assign name="l.settings:query:query" value="'UPDATE ' $ g.Store_Table_Prefix $ 'BasketItems SET code = ? WHERE line_id = ?'" />
<mvt:assign name="l.settings:query:bind_parameters[1]" value="l.settings:item:parts[1]:code" />
<mvt:assign name="l.settings:query:bind_parameters[2]" value="l.settings:item:line_id" />
<mvt:item name="sql" param="l.settings:query"/>
<mvt:comment>
| Update the current page's `l.settings:basket:items[]:code` and `l.settings:basket:groups[]:code` values for the current element
</mvt:comment>
<mvt:assign name="l.settings:item:code" value="l.settings:item:parts[1]:code" />
<mvt:assign name="l.result" value="miva_array_search( l.settings:basket:groups, POS1, l.group, 'l.settings:item:code EQ l.group:code' )" />
<mvt:assign name="l.group:code" value="l.settings:item:parts[1]:code" />
</mvt:if>
</mvt:foreach>