Miva Merchant Modules and Development
Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

SHIPPING: Save Shipping Selection If Customer Edits Order From OPAY

Scot Ranney • June 07, 2024


Simple use of basket custom fields to save the shipping selection if the customer decides to edit their order from the OPAY screen. Utterly useless in my opinion but a client requested it so here's the code.

OPAY

<mvt:comment>
#
# the following two lines are stock miva smt to save order instructions, so let's add our shipping method save under this
#
</mvt:comment>
<mvt:item name="customfields" param="Write_Basket('order_instructions', g.order_instructions)"/>
<mvt:item name="customfields" param="Read_Basket('order_instructions', g.order_instructions)"/>

<mvt:comment>
#
# save our shipping method to a basket field so we can auto select it in case they edit their order from OPAY
#
</mvt:comment>

<mvt:item name="customfields" param="Write_Basket('ShippingMethod', g.ShippingMethod)"/>
<mvt:item name="customfields" param="Read_Basket('ShippingMethod', g._ShippingMethod)"/>

OSEL

First add the "read" basket field above the shipping methods form:

<mvt:comment>
#
# we saved g.ShippingMethod as a custom basket field on OPAY. If they edit their cart info this should give them the same
# shipping method as previously selected. We read into g._ShippingMethod instead of g.ShippingMethod so we don't confuse miva merchant.
#
</mvt:comment>

<mvt:item name="customfields" param="Read_Basket('ShippingMethod', g._ShippingMethod)" />

<form class="t-osel-form" method="post" action="&mvte:urls:OPAY:secure;">

Next, find the loop and update the l.pos1 condition to include whether or not we have g._ShippingMethod

<mvt:if expr="pos1 EQ 1 AND NOT g._shippingmethod">

Finally, after the mvt:else for the condition above, we wrap the radio input in a condition that tests for g._ShippingMethod

<mvt:if expr="g._shippingmethod EQ l.settings:method:module >
	<input class="c-form-checkbox__input" type="radio" name="ShippingMethod" value="&mvte:method:module;:[sbmvte:method:code]" checked>
<mvt:else>
	<input class="c-form-checkbox__input" type="radio" name="ShippingMethod" value="&mvte:method:module;:&mvte:method:code;">
</mvt:if>

https://www.scotsscripts.com/mvblog/shipping-save-shipping-selection-if-customer-edits-order-from-opay.html

mvkb_shadows mvkb_shipping mvkb_smt