Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mini cart builder (AIM'N AUSTRALIA) - Shopify and Ajax Cart (UNCOMPILED, UNBABELED)
var mycart, myitems, myprice, mytotal;
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
/* FIND THE UNCOMPILED, UNBABELED VERSION HERE ---> https://gist.github.com/jacopo-nosto/2e9f527b37a81b43b2b29b2beaff4247 */
function miniCartBuilder(elem) {
if(_targetWindow.jQuery('.ajaxcart__inner').length == 0){
_targetWindow.jQuery('#CartContainer').empty().html('<h3 class="count-1">1 item<span>s</span> in bag</h3><form action="/cart" method="post" novalidate="" class="cart ajaxcart"> <div class="ajaxcart__inner"> </div><div class="ajaxcart__footer"> <div class="row"> <div class="item"> <p>Subtotal</p></div><div class="item"> <p class="price"></p></div></div><p class="shipping">Shipping &amp; taxes calculated at checkout</p><a class="btn--secondary btn--full cart__checkout button button-primary" href="/cart">Checkout</a> </div></form>');
} else {
_targetWindow.jQuery('.ajaxcart__inner').empty();
}
mycart = _targetWindow.jQuery.getJSON('/cart.js');
setTimeout(function () {
myitems = mycart.responseJSON;
mytotal = numberWithCommas(parseInt(myitems.total_price) / 100);
for (var i = 0; i < myitems.items.length; i++) {
myprice = parseInt(myitems.items[i].line_price) / 100;
_targetWindow.jQuery('.ajaxcart__inner').append("<div class='ajaxcart__product'>\n <div class='ajaxcart__row' data-line='1'>\n <div class='row'>\n <div class='item'>\n <a href='https://aimn-au.com/".concat(myitems.items[i].handle, "' class='ajaxcart__product-image'><img src='").concat(myitems.items[i].image, "' alt=''></a>\n </div>\n <div class='item'>\n <a href='https://aimn-au.com/").concat(myitems.items[i].handle, "?variant=").concat(myitems.items[i].variant_id, "' class='ajaxcart__product-name'>").concat(myitems.items[i].product_title, "</a>\n \n <span class='ajaxcart__product-meta'>Size: ").concat(myitems.items[i].variant_title, "</span>\n <div class='row'>\n <div class='ajaxcart__qty'>\n <button type='button' class='ajaxcart__qty-adjust ajaxcart__qty--minus icon-fallback-text' data-id='' data-qty='0' data-line='1'>\n <span class='icon-circle-minus' aria-hidden='true'></span>\n <span class='fallback-text hidden' aria-hidden='true'>\u2212</span>\n <span class='hidden'>translation missing: en.cart.general.reduce_quantity</span>\n </button>\n <input type='text' name='updates[]' class='ajaxcart__qty-num' value='").concat(myitems.items[i].quantity, "' min='0' data-id='30950249431130:5f24caf2f6ac087800efb29c1dd91f69' data-line='").concat(myitems.items[i].quantity, "' aria-label='quantity' pattern='[0-9]*'>\n <button type='button' class='ajaxcart__qty-adjust ajaxcart__qty--plus icon-fallback-text' data-id='30950249431130:5f24caf2f6ac087800efb29c1dd91f69' data-line='1' data-qty='2'>\n <span class='icon-plus-circle' aria-hidden='true'></span>\n <span class='fallback-text hidden' aria-hidden='true'>+</span>\n <span class='hidden'>translation missing: en.cart.general.increase_quantity</span>\n </button>\n </div>\n\n <div class='ajaxcart__price'>\n \n <span class='price'>&#36;").concat(myprice, "</span>\n \n </div>\n\n \n </div>\n </div>\n </div>\n </div>\n </div>"));
}
_targetWindow.jQuery('.ajaxcart__footer .price').html('&#36;' + mytotal);
_targetWindow.jQuery('#basketToggle #CartCount').html(myitems.item_count);
_targetWindow.jQuery('#cart-container h3').html(myitems.item_count + ' ITEM <span>S</span> in bag');
/* ADDING TO <html> THE CLASS offCanvasBasket IN ORDER TO TOGGLE THE MINI CART */
_targetWindow.jQuery(_targetWindow.document).find("html").addClass("offCanvasBasket");
elem.innerHTML = elem.getAttribute("swatchsize");
}, 1500);
}
function nostoAddToCart(skuid, el){
var http = new XMLHttpRequest();
var url = 'https://aimn-au.com/cart/add.js?quantity=1&id=' + skuid;
http.open('POST', url, true);
el.innerHTML = '<div class="nosto-loader"></div>'
http.setRequestHeader('Content-type', 'text/javascript; charset=utf-8');
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
miniCartBuilder(el);
}
}
http.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment