Last active
July 5, 2022 09:18
-
-
Save paul-phan/c76cfd6bcd3c6291d33891a50c21245c to your computer and use it in GitHub Desktop.
pagefly-atc-shopify.js
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
// nathan theme | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
$.get("/cart?view=json", function(data, status) { | |
/*optional stuff to do after success */ | |
$(".widget_shopping_cart_content").html(data); | |
}).always(function() { | |
var subtotal = parseFloat( | |
$(".widget_shopping_cart_body").data("subtotal") | |
); | |
$(".gecko-cart-subtotal >span").html( | |
elessiShopifyPre.formatMoney(subtotal, nathan_settings.moneyFormat) | |
); | |
$(".cartCount").html($(".widget_shopping_cart_body").data("count")); | |
elessiShopify.favicon_counter( | |
parseInt($(".widget_shopping_cart_body").data("count")) | |
); | |
elessiShopify.nanoScroller(); | |
if ( | |
nathan_settings.show_multiple_currencies && | |
elessiShopifyPre.StorageCurrency() !== null | |
) { | |
Currency.convertAll( | |
shopCurrency, | |
elessiShopifyPre.StorageCurrency(), | |
".widget_shopping_cart_content span.money" | |
); | |
Currency.convertAll( | |
shopCurrency, | |
elessiShopifyPre.StorageCurrency(), | |
".gecko-cart-subtotal span.money" | |
); | |
} | |
elessiShopify.initAddToCart( | |
__pagefly_helper_store__.lastATCResult.product_id | |
); | |
}); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// Narative theme | |
// need to put the cart on to window | |
var cart = window.cart = {} | |
// then add this code to the bottom of js file. | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
window.cart && | |
window.cart._promiseChange({ | |
url: "/cart.json", | |
dataType: "json" | |
}); | |
window.theme.sections.instances[0]._openCartDrawer(new Event("click")); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// theme Modular | |
var Cart = window.cart = {} | |
// then add this code to the bottom of js file. | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
cart.getCart(cart.buildCart); | |
if ($(window).width() > 550) { | |
cart.popover.show(__pagefly_helper_store__.lastATCResult); | |
} | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// Some unnamed theme. | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
theme.ProductPage._updateCartCount(); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
document.body.dispatchEvent( | |
new CustomEvent("product:added", { | |
bubbles: true, | |
detail: { | |
variant: __pagefly_helper_store__.lastATCResult.variant_id, | |
quantity: __pagefly_helper_store__.lastATCResult.quantity | |
} | |
}) | |
); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
Shopify.getCart(function(cart) { | |
Shopify.updateCartInfo(cart, ".cart-info .cart-content"); | |
}); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// Fastor theme | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
roar.updateCartSidebar(); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
Shopify.onItemAdded(__pagefly_helper_store__.lastATCResult) | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
$.ajax({ | |
url: "/cart.js", | |
dataType: "json", | |
cache: false, | |
success: function success(cart) { | |
refreshCart(cart); | |
window.setTimeout(function() { | |
$.fancybox.close(); | |
$(".cart-button").click(); | |
}, 500); | |
} | |
}); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// Booster theme | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
$.getJSON("/cart.json", function(cart) { | |
var total_price = cart.total_price; | |
$("#CartCost").text( | |
theme.Currency.formatMoney(total_price, theme.moneyFormat) | |
); | |
$("#CartCount > span").text(cart.item_count); | |
}); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
Shopify.theme.jsAjaxCart.showDrawer(); | |
Shopify.theme.jsAjaxCart.updateView(); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
window.__pagefly_help.getCart(console.log); | |
window.__pagefly_help.notification( | |
window.__pagefly_helper_store__.lastATCResult | |
); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
// Trademark | |
$.getJSON('/cart.js', cart => { | |
$(document).trigger('theme:cart:updated', [cart, true, true]); | |
}) | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
roar.updateCart(__pagefly_helper_store__.lastATCResult, true); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
$('body').trigger('added.ajaxProduct'); | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
$.getJSON("/cart", function(cart) { | |
StyleHatch.AjaxCart.updateCartButton(cart); | |
StyleHatch.AjaxCart.updateCartPreview( | |
JSON.stringify(__pagefly_helper_store__.lastATCResult), | |
cart | |
); | |
}); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
try { | |
setTimeout(function() { | |
window.__pagefly_helper_store__ && | |
window.__pagefly_helper_store__.subscribe(function(c) { | |
theme.partials.Cart.updateAllHtml(function() {}); | |
theme.partials.Cart.updateTotals(); | |
$('[data-off-canvas--open="right-sidebar"]') | |
.first() | |
.trigger("click"); | |
}); | |
}, 1500); | |
} catch (e) { | |
console.warn(e); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment