Last active
March 4, 2022 09:10
-
-
Save smant/e31ea16e62c3e4b92ada990e709f316d to your computer and use it in GitHub Desktop.
Getsitecontrol Ticimax cart watcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cartWatcher(cb){ | |
function getCartParams(){ | |
let ctp,cc | |
try{ | |
c = window.cart.get.model.cart | |
ctp = parseFloat(c.totalAmountStr.replaceAll(/[^\d\.\,]/,'')) | |
cc = c.products[0].currency | |
}catch{} | |
return { | |
cartTotalPrice: ctp, | |
cartCurrency: cc | |
} | |
} | |
let current = {} | |
setInterval(function(){ | |
let params = getCartParams() | |
if (params && JSON.stringify(current)!=JSON.stringify(params)){ | |
current = params | |
cb(params) | |
} | |
}, 1000) | |
} | |
window.gsc=window.gsc||function(){ (gsc.q=gsc.q||[]).push(arguments)}; | |
cartWatcher(function(params){window.gsc('params', params)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment