Order tagging issue

Highlighted
New Member
1 0 0

Hello,

I am developing an app for a client that automatically validates addresses. When an address is invalid it is supposed to tag the order with sl-invalid-address.

 

The below code is present in the checkout.liquid file

 

I tried to accomplish that with this script && function:

<script type="text/javascript">
if (sessionStorage.getItem("need_to_tag") === null){
setSessionVariable("need_to_tag", "true")
}


let tagOrder = (timesRan,stringTag) => {
let timesRepeated = timesRan
var params = {
type: 'POST',
url: '/cart/update.js',
data: {note: stringTag},
dataType: 'json',
success: function() {
if (timesRepeated < 3){
timesRepeated+=1
tagOrder(timesRepeated,stringTag)
}
},
error: function() {
console.error("tag failure")
if (timesRepeated < 3){
timesRepeated+=1
tagOrder(timesRepeated,stringTag)
}
}
};
jQuery.ajax(params)
}

function setSessionVariable(cname, cvar) {
sessionStorage.setItem(cname,cvar)
}
if (sessionStorage.getItem("need_to_tag") === "true"){
setTimeout(function (){tagOrder(1,"sl-invalid-address")},100)
}
else {
setTimeout(function (){tagOrder(1,null)},100)
}

</script>
In another script:

let
tagOrdertagOrderParent = (timesRan,stringTag) => {
let timesRepeated = timesRan
var params = {
type: 'POST',
url: '/cart/update.js',
data: {note: stringTag},
dataType: 'json',
success: function() {
if (timesRepeated < 3){
timesRepeated+=1
tagOrdertagOrderParent(timesRepeated,stringTag)
}
else {
document.querySelector('button[data-trekkie-id="continue_to_shipping_method_button"]').click()
}
},
error: function() {
console.error("tag failure")
if (timesRepeated < 3){
timesRepeated+=1
tagOrdertagOrderParent(timesRepeated,stringTag)
}
}
};
jQuery.ajax(params)
}

The first script runs immediately when the page loads, the second function is called in certain parts of the workflow.

 

This tags the order fine when it's the first checkout a user attempts however on subsequent checkouts within the same browser session it tags the order how the previous order should have been tagged rather than tagging it properly.

 

0 Likes