Skip to content

Instantly share code, notes, and snippets.

@Sally165
Created April 21, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sally165/caa88a839bc70aead266a9af94230db6 to your computer and use it in GitHub Desktop.
Save Sally165/caa88a839bc70aead266a9af94230db6 to your computer and use it in GitHub Desktop.
<!-- PAGEFLY CART HELPER - DO NOT DELETE -->
<script>
function refreshCart() {
const el = document.querySelector('[data-cart-mini]');
var $deferred = shopify_asyncview_dist_index_es.load(window.Theme.routes.cart_url, 'mini').done(function (data) {
el.querySelector('[data-cart-mini-content]').innerHTML = data.html.content;
el.querySelector('[data-cart-mini-footer]').innerHTML = data.html.footer;
var removeButtons = document.querySelectorAll('.cart-mini-item-remove').forEach(btn => {
btn.addEventListener('click', event => {
console.log('check url',event);
var url = "".concat(window.Theme.routes.cart_change_url, ".js");
jquery_default.a.post(url, {
id: event.currentTarget.getAttribute('data-cart-mini-item-remove'),
quantity: 0
}, function () {
refreshCart();
})
});
})
})
}
try {
setTimeout(function () {
window.__pagefly_helper_store__ &&
window.__pagefly_helper_store__.subscribe(function (res) {
$.getJSON('/cart.json').then(cart => {
$('[data-cart-mini-count]').text(cart.item_count);
refreshCart();
});
});
}, 2500);
} catch (e) {
console.warn(e);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment