Skip to content

Instantly share code, notes, and snippets.

@smant
Last active March 4, 2022 09:10
Show Gist options
  • Save smant/e31ea16e62c3e4b92ada990e709f316d to your computer and use it in GitHub Desktop.
Save smant/e31ea16e62c3e4b92ada990e709f316d to your computer and use it in GitHub Desktop.
Getsitecontrol Ticimax cart watcher
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