Miva Merchant Development by Scot's Scripts

SHIPPING: Save Shipping Selection If Customer Edits Order From OPAY

Miva Random Code Trivia

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.

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)
SEO Audit & Inquiries • News & Updates • SEO for Miva Merchant

SHIPPING: Save Shipping Selection If Customer Edits Order From OPAY

THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.

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

shadows shipping smt