try {
ytShellConfig = {"cartTitle":"Your Cart","cartBackgroundColor":"#FFFFFF","exploreCtaColor":"#000000","enableCustomCart":true,"recommendedProductsList":{"productHandles":[]},"checkoutType":"gokwik","showBackdrop":true,"discountInCheckoutButton":true,"ctaButtonBackgroundColor":"#151144","ctaButtonTextColor":"#FFFFFF","primaryTextColor":"#000000","productRecsCtaButtonText":"Add to cart","productRecsTitleText":"PEOPLE ALSO BOUGHT 🤩","emptyProductRecsTitleText":"Your Cart is Empty 😔, Add these Now! ✨","productRecsCardLayout":"vertical","productRecsCardListVariant":"scroll","secondaryTextColor":"#1A1A1A","showProductRecsOnDesktop":true,"showProductRecsOnMobile":true,"showEmptyCartRecommendations":true,"themeColor":"#151144","themeTextColor":"#ffffff","showGSTOption":false,"enableCustomCartOpenOnProductAdd":true,"showNoteOption":false,"showEditOptionOnProducts":false,"showVariantSelectionDropdownInProductRecs":true,"postalCodeList":[],"enableGeoLocationRestriction":false,"showStickyAddToCart":false,"cartGeoLocationValidatorData":{},"enableCustomCartOnCartPage":true,"showCartTimer":false,"cartTimerData":{"showTimer":true,"minutes":5,"customText":"Your products are reserved in cart for"},"cartComponentsCornerType":"rounded","cartComponentsCornerRadius":9,"giftWrapData":{},"stickyAddToCartProductBarData":{"showPrice":true,"productImage":{"id":"","path":""},"topRibbonText":"","buyNowCtaTitle":"Buy Now","desktopBarType":"stretch","excludeProducts":[],"showProductName":true,"showBarOnDesktop":true,"showBuyNowButton":false,"showProductImage":true,"addToCartCtaTitle":"Add to Cart","ctaButtonFontSize":18,"showAddToCartButton":true,"showVariantSelector":false,"fullyAppearsAtHeight":400,"showStickyProductBar":true,"productInfoVisibility":true,"startsAppearingAtHeight":200},"cartOffersCarousalData":{"enableCartOffersCarousel":true,"slidesCount":3,"pauseTimer":5,"backgroundColor":"#242424","primaryTextColor":"","secondaryTextColor":"","slides":[{"slideNumber":1,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"14 days Easy Return \u0026 Exchnage ","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]},{"slideNumber":2,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"✅ Free Shipping","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]},{"slideNumber":3,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"✅ COD Available ","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]}]},"freebieMilestoneData":{},"freebieClaimData":{},"floatingCartData":{},"checkoutSectionData":{},"drawerLayoutData":{},"cartGstSectionData":{},"bxgyDiscountsEnabled":false};
if (!ytShellConfig || typeof ytShellConfig !== 'object') {
ytShellConfig = null;
}
} catch(e) {}
const ytShellCustomCartEnabled = ytShellConfig &&
ytShellConfig.enableCustomCart &&
ytShellConfig.enableCustomCart !== 'false';
const ytShellCountryEligible = (window.Shopify && window.Shopify.country === 'IN') ||
(window.Shopify && window.Shopify.shop === 'jagat-pharma-global.myshopify.com');
const ytShellShouldInit = ytShellCustomCartEnabled && !ytCartShellIsCartPage && ytShellCountryEligible;
const ytShellShouldAutoOpen = ytShellShouldInit &&
ytShellConfig.enableCustomCartOpenOnProductAdd !== false &&
ytShellConfig.enableCustomCartOpenOnProductAdd !== 'false';
// Global shell state for widget synchronization
window.ytCartShellState = { isOpen: false, takenOver: false };
// Liquid-rendered cart data — available instantly, no AJAX needed
var ytShellInitialCart = {
items: [
],
total: 0,
count: 0,
currency: "₹"
};
if (ytShellShouldInit) {
(function() {
var shellBgColor = (ytShellConfig && ytShellConfig.cartBackgroundColor) || '#ffffff';
var shellTitle = (ytShellConfig && ytShellConfig.cartTitle) || 'My Cart';
var shellTextColor = (ytShellConfig && ytShellConfig.primaryTextColor) || '#000000';
var shellShowBackdrop = ytShellConfig.showBackdrop !== false && ytShellConfig.showBackdrop !== 'false';
var shellCheckoutType = (ytShellConfig && ytShellConfig.checkoutType) || 'shopify';
var shellThemeColor = (ytShellConfig && ytShellConfig.themeColor) || '#000000';
var shellThemeTextColor = (ytShellConfig && ytShellConfig.themeTextColor) || '#ffffff';
var shellCornerType = (ytShellConfig && ytShellConfig.cartComponentsCornerType) || '';
var shellCornerRadius = (ytShellConfig && ytShellConfig.cartComponentsCornerRadius) || 0;
var shellBgSubdued = (ytShellConfig && ytShellConfig.backgroundSubdued) || '#e1e1e1';
var switchWidthVariantEnabled = (ytShellConfig && ytShellConfig.switchWidthVariant) || false;
// Mutable cart state — starts from Liquid, updated on ATC via /cart.js
var shellCartData = {
items: ytShellInitialCart.items.slice(),
total: ytShellInitialCart.total,
count: ytShellInitialCart.count,
currency: ytShellInitialCart.currency
};
var cartSelectors = [
'a[href="/cart"]',
'button.tt-dropdown-toggle',
'a.area--cart',
'a.hcart',
'a.js-drawer-open-cart',
'a.cart-icon-bubble',
'a[title="Cart"]',
'.site-header__link.site-header__cart.js-mini-cart.cardraw',
'a#offcanvas-cart-icon',
'span.js-toggle-cart',
'div.single-icon.cart',
'a#cart-icon-bubble',
'a.cart-count',
'button.qsc2-basic.qsc2-stickybtn',
'svg.icon-bag',
'a.icon-bubble[aria-label=cart]',
'div.mini-cart-icon a.ltn__utilize-toggle',
'button#CartButton',
'span#cart-icon-bubble',
'a[onclick="window.openCartCheckout()"]',
'div.cart-fixed.cart-icon',
'a[onclick="window.openCart()"]',
'a.js-call-minicart',
'button[data-sidebar-id="CartDrawer"]',
'a.icon-cart-arrow',
'a[data-js-sidebar-handle][title="Open cart"]',
'button.js-mini-cart-trigger',
'div.site-header__cart-icon',
'a[onclick*="cart-drawer"]',
'button.cart-icon',
'xo-tooltip[xo-title="Cart"]',
'a i.fa-shopping-bag',
'cart-icon',
'div#cart-icon-bubble',
'a.flo-header-cart-btn',
'a[onclick="window.handleFloCartBtn()"]'
];
var formBasedATCSelectorList = [
'button.product-form__submit', 'button.btn-addtocart', 'button.tt-btn-addtocart',
'button.m-add-to-cart', 'button.add-to-cart', 'button#bundleBtn.btn',
'div.lc-product-button', 'button.add-to-cart-btn', 'button.stick-add',
'button.btn.btn--large.add-to-cart', 'button.ProductForm__AddToCart',
'a#atc-coll', 'button#AddToCart', 'button[data-pf-type=ProductATC2]',
'button.js-product-button-add-to-cart', 'button.button-action--shadow',
'button.add-cart-btn', 'input[value="Add to cart"]', 'div.cart-block-click',
'button.pf-button-1', 'button.product-form--atc-button', 'button.addtocartqv',
'button.btn--quick.pill', 'button[name=add]', 'button.add_to_cart_button',
'button.product-item__quick-add', 'button.gp-button-atc', 'button.product-ATC-Button',
'button.cbb-frequently-bought-add-button', 'button.single_add_to_cart_button'
];
var quickAddToCartElements = [
'.t4s-svg-pr-icon', '.product-card__overlay-btn.js-grid-cart', 'button.product-ATC-Button',
'button.quick-add__submit .span', 'button[x-html=atcBtnText]', 'button.product-item__quick-add',
'a.add-to-cart', 'a[data-trigger=addtocart]', 'add-to-cart.button',
'button.product-card--add-to-cart-button', 'div.pr_atc', 'button.enj-add-to-cart-btn',
'div.product-button', 'button.product-grid-item__btn', 'input.product__add-button',
'button.addtocart-btn', 'a.t4s-pr-item-btn', 'button.form__send__button',
'quick-add', 'button.addtocart_button', 'button.qv-add-button', 'a.product-form__submit',
'button.quick-add__submit', 'div.buttonz', 'button[class^="video-add"]'
];
var allAtcSelectors = formBasedATCSelectorList.concat(quickAddToCartElements);
var shellOverlay = null;
var shellDrawer = null;
var shellObserver = null;
var origAssign = null;
var origReplace = null;
var shellPrevHistoryState = null;
var shellPrevUrl = null;
var closeSvg = '
';
// ---- Helpers ----
function escapeShellHtml(str) {
if (!str) return '';
return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}
function formatShellPrice(cents) {
var amount = (cents / 100).toFixed(2);
var parts = amount.split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
// ---- Render Shell Cart HTML ----
function renderShellCartContent() {
var items = shellCartData.items;
var total = shellCartData.total;
var count = shellCartData.count;
var currency = shellCartData.currency;
var btnRadius = shellCornerType === 'rounded' ? shellCornerRadius + 'px' : '0px';
// Header
var html = '
';
html += '
';
html += '
';
html += escapeShellHtml(shellTitle);
if (count > 0) {
html += ' ' + count + ' ';
}
html += ' ';
html += '
';
html += closeSvg;
html += '
';
html += '
';
html += '
';
if (count === 0) {
// Empty cart
html += '
';
html += '
Your cart is empty
';
html += '
';
return html;
}
// 12px grey separator (above items)
html += '
';
// Scrollable items area
html += '
';
for (var i = 0; i < items.length; i++) {
var item = items[i];
var isLast = i === items.length - 1;
// Item wrapper (matches ProductCardWrapper with after-pseudo divider)
html += '
';
// StyledDiv (matches ProductCard layout)
html += '
';
// ProductImageWrapper
html += '
';
// ProductImage (matches yt-cart-product-image)
html += '
';
if (item.image) {
html += '
';
} else {
html += '
';
}
html += '
';
// QuantityBadge
html += '
' + item.quantity + '
';
html += '
'; // end ProductImageWrapper
// Content column
html += '
';
// Title
html += '' + escapeShellHtml(item.title) + ' ';
// Price
html += '' + currency + formatShellPrice(item.price) + ' ';
html += '
'; // end content column
html += '
'; // end StyledDiv
html += '
'; // end item wrapper
// Divider between items+
if (!isLast) {
html += '
';
}
}
html += '
';
html += '
'; // end scrollable
// Footer
html += ''; // end footer
return html;
}
// ---- Bind shell event listeners (called after every render) ----
function bindShellEvents() {
var closeBtn = document.getElementById('yt-cart-shell-close-btn');
if (closeBtn) {
closeBtn.addEventListener('click', function() { window.openYtCustomCart(false); });
}
var checkoutBtn = document.getElementById('yt-shell-checkout-btn');
if (checkoutBtn) {
checkoutBtn.addEventListener('click', handleShellCheckout);
}
}
// ---- Checkout handler (respects checkoutType from metafield) ----
function handleShellCheckout(e) {
try {
switch (shellCheckoutType) {
case 'gokwik':
if (window.gokwikSdk && window.gokwikSdk.initCheckout && window.merchantInfo) {
window.gokwikSdk.initCheckout(window.merchantInfo);
} else if (window.gokwikSdk && window.gokwikSdk.initCheckout) {
window.gokwikSdk.initCheckout(e.target);
} else {
window.location.replace('/checkout');
}
break;
case 'razorpay':
if (window.openRzpCheckout) { window.openRzpCheckout(); }
else if (window.openRzpLogin) { window.openRzpLogin(); }
else { window.location.replace('/checkout'); }
break;
case 'breeze':
if (window.breeze && window.breeze.startCheckout) { window.breeze.startCheckout(); }
else { window.location.replace('/checkout'); }
break;
case 'shopflo':
if (window.handleFloCheckoutBtn) { window.handleFloCheckoutBtn(); }
else { window.location.replace('/checkout'); }
break;
case 'shiprocket':
if (window.HeadlessCheckout && window.HeadlessCheckout.checkout) { window.HeadlessCheckout.checkout(e); }
else { window.location.replace('/checkout'); }
break;
case 'zecpay':
if (window.handleOcc) { window.handleOcc(); }
else { window.location.replace('/checkout'); }
break;
case 'flexype':
if (window.openFlexyCheckout) { window.openFlexyCheckout(); }
else { window.location.replace('/checkout'); }
break;
case 'nimbbl':
if (window.nimbblOpenCheckout) { window.nimbblOpenCheckout(); }
else { window.location.replace('/checkout'); }
break;
case 'shopify':
default:
window.location.replace('/checkout');
}
} catch (err) {
console.warn('Shell checkout failed, redirecting to Shopify checkout', err);
window.location.replace('/checkout');
}
}
// ---- Refresh shell from /cart.js (called after ATC) ----
function refreshShellCart() {
return fetch('/cart.js', { credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(data) {
shellCartData.items = (data.items || []).map(function(item) {
return {
title: item.product_title || item.title || '',
image: item.image || '',
quantity: item.quantity || 1,
price: item.final_line_price || 0,
url: item.url || ''
};
});
shellCartData.total = data.total_price || 0;
shellCartData.count = data.item_count || 0;
var skeleton = document.getElementById('yt-cart-shell-skeleton');
if (skeleton && !window.ytCartShellState.takenOver) {
skeleton.innerHTML = renderShellCartContent();
bindShellEvents();
}
})
.catch(function() {});
}
// ---- Create Shell DOM ----
function createShell() {
if (shellDrawer) return;
var style = document.createElement('style');
style.id = 'yt-cart-shell-styles';
style.textContent =
'@media screen and (max-width: 720px) { #yt-cart-shell-drawer { width: 350px !important; } }' +
'@media screen and (max-width: 450px) { #yt-cart-shell-drawer { width: ' + (switchWidthVariantEnabled ? '100%' : '91%') + ' !important; max-width: ' + (switchWidthVariantEnabled ? '100%' : '97%') + ' !important; } }' +
'#yt-cart-shell-drawer * { box-sizing: border-box; }' +
'#yt-cart-shell-drawer .yt-cart-product-image img { width: 100%; height: 100%; object-fit: cover; }' +
'@media screen and (max-width: 480px) { #yt-cart-shell-drawer .yt-cart-product-image { width: 65px !important; } }' +
'#yt-cart-shell-drawer .yt-shell-item-title { display: -webkit-box !important; -webkit-line-clamp: 2 !important; -webkit-box-orient: vertical !important; overflow: hidden !important; font-size: 14px !important; font-weight: 500 !important; line-height: 1.4 !important; }' +
'.yt-shell-pulse { animation: ytShellPulse 1.5s ease-in-out infinite; }' +
'@keyframes ytShellPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }' +
'button.yt-checkout-button { background-image: none !important; min-height: auto !important; line-height: normal !important; }';
document.head.appendChild(style);
shellOverlay = document.createElement('div');
shellOverlay.id = 'yt-cart-shell-overlay';
shellOverlay.setAttribute('style',
'position:fixed !important;top:0 !important;left:0 !important;right:0 !important;bottom:0 !important;' +
'z-index:10000 !important;background-color:rgba(0,0,0,0.5) !important;display:none;width:100% !important;height:100% !important;'
);
shellOverlay.addEventListener('click', function() { window.openYtCustomCart(false); });
shellDrawer = document.createElement('div');
shellDrawer.id = 'yt-cart-shell-drawer';
shellDrawer.setAttribute('style',
'position:fixed !important;top:0 !important;right:0 !important;z-index:2147483643 !important;' +
'height:100% !important;width:457px;max-width:457px;background-color:' + shellBgColor + ' !important;' +
'transition:transform 0.3s ease !important;transform:translateX(100%) !important;' +
'box-shadow:none;font-family:inherit;line-height:normal;overflow:hidden;'
);
shellDrawer.innerHTML =
'
' +
renderShellCartContent() +
'
' +
'
';
document.body.appendChild(shellOverlay);
document.body.appendChild(shellDrawer);
bindShellEvents();
}
// ---- Open / Close Shell ----
function openShell() {
if (!shellDrawer || window.ytCartShellState.isOpen) return;
shellDrawer.style.setProperty('transform', 'translateX(0)', 'important');
shellDrawer.style.boxShadow = '-14px 8px 14.4px 0px rgba(0, 0, 0, 0.35)';
if (shellShowBackdrop && shellOverlay) shellOverlay.style.display = 'block';
document.body.classList.add('drawer-open');
shellPrevHistoryState = window.history.state;
shellPrevUrl = window.location.href;
window.history.pushState({ ytCustomCartDrawer: 'open' }, '');
window.ytCartShellState.isOpen = true;
}
function closeShell() {
if (!shellDrawer || !window.ytCartShellState.isOpen) return;
shellDrawer.style.setProperty('transform', 'translateX(100%)', 'important');
shellDrawer.style.boxShadow = 'none';
if (shellOverlay) shellOverlay.style.display = 'none';
document.body.classList.remove('drawer-open');
if (window.history.state && window.history.state.ytCustomCartDrawer === 'open') {
window.history.replaceState(shellPrevHistoryState, '', shellPrevUrl || window.location.href);
}
window.ytCartShellState.isOpen = false;
}
// Back button closes shell
window.addEventListener('popstate', function() {
if (window.ytCartShellState.isOpen && !window.ytCartShellState.takenOver) {
closeShell();
}
});
// Global cart opener — available immediately, before widget loads.
// After widget takes over (takenOver=true), this becomes a no-op
// and the widget's React setState is used instead.
window.openYtCustomCart = function(open) {
if (window.ytCartShellState.takenOver) return;
if (open) openShell(); else closeShell();
};
// Expose shell control API for the widget to manage the container
window.ytCartShell = {
open: openShell,
close: closeShell,
getDrawerElement: function() { return shellDrawer; },
getOverlayElement: function() { return shellOverlay; },
cleanup: function() {
// Disconnect MutationObserver
if (shellObserver) { shellObserver.disconnect(); shellObserver = null; }
// Restore fetch
if (origFetch) { window.fetch = origFetch; }
// Restore XHR
if (xhrProtoOpen) { OrigXHR.prototype.open = xhrProtoOpen; }
if (xhrProtoSend) { OrigXHR.prototype.send = xhrProtoSend; }
// Restore location methods
if (origAssign) { window.location.assign = origAssign; }
if (origReplace) { window.location.replace = origReplace; }
// Restore jQuery ajax
if (origJqAjax && window.jQuery) { window.jQuery.ajax = origJqAjax; }
}
};
// ---- Universal Cart Icon Interception ----
function handleShellCartClick(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
window.openYtCustomCart(true);
}
function interceptCartIcons() {
var allSelectors = cartSelectors.join(', ');
var atcSelectorsStr = allAtcSelectors.join(', ');
function handleAtcClick(e) {
if (window.ytCartShellState.takenOver) return;
var currentCount = shellCartData.count;
var attempts = 0;
var maxAttempts = 30;
function checkCart() {
fetch('/cart.js', { credentials: 'same-origin' })
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.item_count > currentCount) {
shellCartData.items = (data.items || []).map(function(item) {
return {
title: item.product_title || item.title || '',
image: item.image || '',
quantity: item.quantity || 1,
price: item.final_line_price || 0,
url: item.url || ''
};
});
shellCartData.total = data.total_price || 0;
shellCartData.count = data.item_count || 0;
var skeleton = document.getElementById('yt-cart-shell-skeleton');
if (skeleton && !window.ytCartShellState.takenOver) {
skeleton.innerHTML = renderShellCartContent();
bindShellEvents();
}
if (ytShellShouldAutoOpen) window.openYtCustomCart(true);
} else if (attempts < maxAttempts) {
attempts++;
setTimeout(checkCart, Math.min(50 + attempts * 25, 500));
}
}).catch(function() {
if (attempts < maxAttempts) {
attempts++;
setTimeout(checkCart, Math.min(50 + attempts * 25, 500));
}
});
}
setTimeout(checkCart, 100);
}
try {
var elements = document.querySelectorAll(allSelectors);
elements.forEach(function(el) {
el.addEventListener('click', handleShellCartClick, true);
if (el.href && (el.href.includes('/cart') || el.href.endsWith('/cart')) && !el.href.includes('/cart/')) {
el._ytOrigHref = el.getAttribute('href');
el.setAttribute('href', 'javascript:void(0)');
}
});
var atcElements = document.querySelectorAll(atcSelectorsStr);
atcElements.forEach(function(el) {
if (el.textContent && el.textContent.toLowerCase().includes('buy')) return;
el.addEventListener('click', handleAtcClick, true);
});
} catch(e) {}
// Delegated click handler catches any cart link, including dynamically added ones
document.addEventListener('click', function(e) {
var target = e.target.closest ? e.target.closest('a') : null;
if (target && target.href) {
try {
var url = new URL(target.href, window.location.origin);
if ((url.pathname === '/cart' || url.pathname.endsWith('/cart')) && !url.pathname.includes('/cart/')) {
e.preventDefault();
e.stopPropagation();
window.openYtCustomCart(true);
}
} catch(err) {}
}
}, true);
// Intercept form submissions to /cart (not /cart/add)
document.addEventListener('submit', function(e) {
var form = e.target;
if (form.action && form.action.includes('/cart') && !form.action.includes('cart/add')) {
e.preventDefault();
e.stopPropagation();
window.openYtCustomCart(true);
}
}, true);
// Intercept programmatic location.assign / location.replace to /cart
origAssign = location.assign.bind(location);
origReplace = location.replace.bind(location);
window.location.assign = function(url) {
if (typeof url === 'string' && (url === '/cart' || url.endsWith('/cart')) && !url.includes('/cart/')) {
window.openYtCustomCart(true);
return;
}
return origAssign(url);
};
window.location.replace = function(url) {
if (typeof url === 'string' && (url === '/cart' || url.endsWith('/cart')) && !url.includes('/cart/')) {
window.openYtCustomCart(true);
return;
}
return origReplace(url);
};
// MutationObserver for dynamically added cart elements
var cartTagNames = { A:1, BUTTON:1, DIV:1, SPAN:1, SVG:1, 'CART-ICON':1, 'XO-TOOLTIP':1 };
var atcTagNames = { A:1, BUTTON:1, INPUT:1, DIV:1, 'ADD-TO-CART':1, 'QUICK-ADD':1 };
var pendingNodes = [];
var rafScheduled = false;
function processPendingNodes() {
rafScheduled = false;
var nodes = pendingNodes;
pendingNodes = [];
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
try {
// Always search children (container may hold matching descendants)
var newEls = node.querySelectorAll ? node.querySelectorAll(allSelectors) : [];
// Short-circuit self-match by tagName
var isSelf = cartTagNames[node.tagName] && node.matches && node.matches(allSelectors);
var allNew = isSelf ? [node].concat(Array.from(newEls)) : Array.from(newEls);
allNew.forEach(function(el) {
el.addEventListener('click', handleShellCartClick, true);
if (el.href && (el.href.includes('/cart') || el.href.endsWith('/cart')) && !el.href.includes('/cart/')) {
el._ytOrigHref = el.getAttribute('href');
el.setAttribute('href', 'javascript:void(0)');
}
});
var newAtcEls = node.querySelectorAll ? node.querySelectorAll(atcSelectorsStr) : [];
var isAtcSelf = atcTagNames[node.tagName] && node.matches && node.matches(atcSelectorsStr);
var allNewAtc = isAtcSelf ? [node].concat(Array.from(newAtcEls)) : Array.from(newAtcEls);
allNewAtc.forEach(function(el) {
if (el.textContent && el.textContent.toLowerCase().includes('buy')) return;
el.addEventListener('click', handleAtcClick, true);
});
} catch(e) {}
}
}
shellObserver = new MutationObserver(function(mutations) {
for (var i = 0; i < mutations.length; i++) {
var addedNodes = mutations[i].addedNodes;
for (var j = 0; j < addedNodes.length; j++) {
if (addedNodes[j].nodeType === 1) pendingNodes.push(addedNodes[j]);
}
}
if (pendingNodes.length && !rafScheduled) {
rafScheduled = true;
requestAnimationFrame(processPendingNodes);
}
});
if (document.body) {
shellObserver.observe(document.body, { childList: true, subtree: true });
}
}
// ---- ATC Fetch Interception (lightweight, before widget loads) ----
var origFetch = window.fetch;
window.fetch = function() {
var url = typeof arguments[0] === 'string' ? arguments[0] :
(arguments[0] && arguments[0].url ? arguments[0].url : '');
var isATC = url.includes('/cart/add.js') || (url.includes('/cart/add') && !url.includes('/cart/add_'));
if (isATC) {
return origFetch.apply(this, arguments).then(function(response) {
if (response.ok) {
// Only handle cart opening before widget takes over.
if (!window.ytCartShellState.takenOver && ytShellShouldAutoOpen) {
refreshShellCart().then(function() {
window.openYtCustomCart(true);
});
}
}
return response;
});
}
return origFetch.apply(this, arguments);
};
// ---- Form Submit Interception for /cart/add ----
document.addEventListener('submit', function(e) {
if (window.ytCartShellState.takenOver) return;
var form = e.target;
if (!form || !form.action) return;
var isCartAdd = form.action.includes('/cart/add');
if (!isCartAdd) return;
// Skip Buy it Now forms , may need to enhance this
var hasDynamicCheckoutBtn = form.querySelector && (
form.querySelector('[data-shopify="payment-button"]') ||
form.querySelector('.shopify-payment-button') ||
form.querySelector('button[name="goto_checkout"]')
);
var hasCheckoutReturnTo = form.querySelector &&
form.querySelector('[name="return_to"][value*="/checkout"]');
if (hasDynamicCheckoutBtn || hasCheckoutReturnTo) return;
e.preventDefault();
e.stopPropagation();
var formData = new FormData(form);
origFetch('/cart/add', {
method: 'POST',
body: formData,
headers: { 'Accept': 'application/json' },
credentials: 'same-origin'
}).then(function(response) {
if (response.ok) {
refreshShellCart().then(function() {
if (ytShellShouldAutoOpen) window.openYtCustomCart(true);
});
}
}).catch(function() {});
}, true);
// ---- jQuery AJAX Interception ----
var origJqAjax = null;
function interceptJqueryAjax() {
if (!window.jQuery || typeof window.jQuery.ajax !== 'function') return;
if (origJqAjax) return;
origJqAjax = window.jQuery.ajax;
window.jQuery.ajax = function() {
var args = Array.prototype.slice.call(arguments);
var ajaxOptions = args[0];
if (typeof ajaxOptions === 'string') {
ajaxOptions = args[1] || {};
ajaxOptions.url = args[0];
}
var url = ajaxOptions.url || '';
if (/\/cart\/(add)(\.js)?/.test(url) && !window.ytCartShellState.takenOver) {
var origComplete = ajaxOptions.complete;
ajaxOptions.complete = function(xhr) {
if ((xhr.status === 200 || xhr.status === 201) && ytShellShouldAutoOpen) {
refreshShellCart().then(function() {
window.openYtCustomCart(true);
});
}
if (typeof origComplete === 'function') {
origComplete.apply(this, arguments);
}
};
}
return origJqAjax.apply(this, args);
};
}
interceptJqueryAjax();
// Re-try after DOM ready in case jQuery loads late
document.addEventListener('DOMContentLoaded', interceptJqueryAjax);
// ---- XMLHttpRequest Interception for /cart/add ----
var OrigXHR = window.XMLHttpRequest;
var xhrProtoOpen = OrigXHR.prototype.open;
var xhrProtoSend = OrigXHR.prototype.send;
OrigXHR.prototype.open = function(method, url) {
this._ytUrl = typeof url === 'string' ? url : '';
this._ytIsCartAdd = /\/cart\/add(\.js)?/.test(this._ytUrl);
return xhrProtoOpen.apply(this, arguments);
};
OrigXHR.prototype.send = function() {
if (this._ytIsCartAdd && !window.ytCartShellState.takenOver) {
var xhr = this;
var origOnLoad = xhr.onload;
var origOnReady = xhr.onreadystatechange;
function handleXHRDone() {
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 201) && ytShellShouldAutoOpen) {
refreshShellCart().then(function() {
window.openYtCustomCart(true);
});
}
}
if (typeof origOnLoad === 'function') {
xhr.onload = function() {
handleXHRDone();
return origOnLoad.apply(this, arguments);
};
} else {
xhr.addEventListener('load', handleXHRDone);
}
}
return xhrProtoSend.apply(this, arguments);
};
// ---- Init ----
createShell();
interceptCartIcons();
})();
}
async function initializeYourToken() {
try {
if (window?.Shopify?.country === 'IN' || window?.Shopify?.shop === 'jagat-pharma-global.myshopify.com') {
const appEmbedContainer = document.createElement('div');
appEmbedContainer.innerHTML = `
`;
document.body.appendChild(appEmbedContainer);
try {
const data = {
customerId: '',
customerEmail: '',
storeId: '27056078908',
storeDomain: 'punekar-cotton.myshopify.com',
storeEmail: 'support@punekarcotton.com',
cartAmount: '0',
cartQty: '0',
enableLoyaltyTiers: null,
tokenCreditPercentage: null,
alternatePaymentRedemptionRate: null,
loyaltyWidgetOpen: null,
widgetThemeColor: null,
brandLogoId: null,
brandLogoPath: null,
r2LogoPath: null,
loyaltyPointsCapOnCartAmount: null,
shopifyStoreTheme: null,
enableRedeemInCartOffers: null,
brandTokenName: null,
widgetRegistrationType: null,
showRegistrationNudge: null,
maxTokensRedeemableAsDiscount: null,
pointsValueWithInr: null,
loyaltyRibbonTextColor: null,
ytCustomCart: {"cartTitle":"Your Cart","cartBackgroundColor":"#FFFFFF","exploreCtaColor":"#000000","enableCustomCart":true,"recommendedProductsList":{"productHandles":[]},"checkoutType":"gokwik","showBackdrop":true,"discountInCheckoutButton":true,"ctaButtonBackgroundColor":"#151144","ctaButtonTextColor":"#FFFFFF","primaryTextColor":"#000000","productRecsCtaButtonText":"Add to cart","productRecsTitleText":"PEOPLE ALSO BOUGHT 🤩","emptyProductRecsTitleText":"Your Cart is Empty 😔, Add these Now! ✨","productRecsCardLayout":"vertical","productRecsCardListVariant":"scroll","secondaryTextColor":"#1A1A1A","showProductRecsOnDesktop":true,"showProductRecsOnMobile":true,"showEmptyCartRecommendations":true,"themeColor":"#151144","themeTextColor":"#ffffff","showGSTOption":false,"enableCustomCartOpenOnProductAdd":true,"showNoteOption":false,"showEditOptionOnProducts":false,"showVariantSelectionDropdownInProductRecs":true,"postalCodeList":[],"enableGeoLocationRestriction":false,"showStickyAddToCart":false,"cartGeoLocationValidatorData":{},"enableCustomCartOnCartPage":true,"showCartTimer":false,"cartTimerData":{"showTimer":true,"minutes":5,"customText":"Your products are reserved in cart for"},"cartComponentsCornerType":"rounded","cartComponentsCornerRadius":9,"giftWrapData":{},"stickyAddToCartProductBarData":{"showPrice":true,"productImage":{"id":"","path":""},"topRibbonText":"","buyNowCtaTitle":"Buy Now","desktopBarType":"stretch","excludeProducts":[],"showProductName":true,"showBarOnDesktop":true,"showBuyNowButton":false,"showProductImage":true,"addToCartCtaTitle":"Add to Cart","ctaButtonFontSize":18,"showAddToCartButton":true,"showVariantSelector":false,"fullyAppearsAtHeight":400,"showStickyProductBar":true,"productInfoVisibility":true,"startsAppearingAtHeight":200},"cartOffersCarousalData":{"enableCartOffersCarousel":true,"slidesCount":3,"pauseTimer":5,"backgroundColor":"#242424","primaryTextColor":"","secondaryTextColor":"","slides":[{"slideNumber":1,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"14 days Easy Return \u0026 Exchnage ","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]},{"slideNumber":2,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"✅ Free Shipping","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]},{"slideNumber":3,"slideType":"TextFieldOnly","textAlignment":"left","titleTextField":"✅ COD Available ","descriptionTextField":"","imageUrl":"","campaignCode":"","criteriaCount":0,"criteria":[]}]},"freebieMilestoneData":{},"freebieClaimData":{},"floatingCartData":{},"checkoutSectionData":{},"drawerLayoutData":{},"cartGstSectionData":{},"bxgyDiscountsEnabled":false},
signinCTAVisibility: true,
currentProduct: {"id":10099705315641,"title":"Dark Blue Colour Signature Shirt For Men","handle":"dark-blue-colour-signature-classic-oxford-shirt-for-men","description":"\u003cp\u003e\u003cmeta charset=\"utf-8\"\u003e\u003cstrong\u003eIntroducing our Signature Classic Oxford Shirt for Men. \u003c\/strong\u003eCrafted from premium cotton oxford fabric, this dark blue shirt delivers refined elegance with everyday practicality. The naturally breathable weave ensures all-day comfort, while the durable construction with stands regular wear and washing. Its versatile design transitions seamlessly from professional settings to casual occasions, making it an essential addition to any wardrobe. The flexible fabric drapes beautifully, offering both structure and ease of movement for the modern man who values quality and sophistication.\u003c\/p\u003e\n\u003cp class=\"selectable-text copyable-text x15bjb6t x1n2onr6\"\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eNeckline\u003c\/strong\u003e: Spread Collar\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eFabric\u003c\/strong\u003e: Cotton Oxford\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eFit\u003c\/strong\u003e: Regular Fit\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003ePattern\u003c\/strong\u003e: Solid\u003cbr\u003e\u003c\/span\u003e\u003cstrong data-end=\"591\" data-start=\"581\"\u003eSleeve\u003c\/strong\u003e: Full \u0026amp; Half Sleeve\u003c\/p\u003e","published_at":"2026-02-04T13:20:42+05:30","created_at":"2026-01-17T18:06:48+05:30","vendor":"Punekar Cotton","type":"Shirts \u0026 Tops","tags":["Classic Oxford","Cotton Oxford","Dark Blue","Dark Blue Classic Oxford Plain Shirt","Dark Blue Cotton Oxford Plain Shirt","Full Sleeves","Oxford Shirt"],"price":134900,"price_min":134900,"price_max":134900,"available":true,"price_varies":false,"compare_at_price":220000,"compare_at_price_min":220000,"compare_at_price_max":220000,"compare_at_price_varies":false,"variants":[{"id":51700428341561,"title":"M\/38 \/ Full","option1":"M\/38","option2":"Full","option3":null,"sku":"PCCLOXDBLU-F-M","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - M\/38 \/ Full","public_title":"M\/38 \/ Full","options":["M\/38","Full"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428374329,"title":"M\/38 \/ Half","option1":"M\/38","option2":"Half","option3":null,"sku":"PCCLOXDBLU-H-M","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - M\/38 \/ Half","public_title":"M\/38 \/ Half","options":["M\/38","Half"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428407097,"title":"L\/40 \/ Full","option1":"L\/40","option2":"Full","option3":null,"sku":"PCCLOXDBLU-F-L","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - L\/40 \/ Full","public_title":"L\/40 \/ Full","options":["L\/40","Full"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428439865,"title":"L\/40 \/ Half","option1":"L\/40","option2":"Half","option3":null,"sku":"PCCLOXDBLU-H-L","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - L\/40 \/ Half","public_title":"L\/40 \/ Half","options":["L\/40","Half"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428472633,"title":"XL\/42 \/ Full","option1":"XL\/42","option2":"Full","option3":null,"sku":"PCCLOXDBLU-F-XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - XL\/42 \/ Full","public_title":"XL\/42 \/ Full","options":["XL\/42","Full"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428505401,"title":"XL\/42 \/ Half","option1":"XL\/42","option2":"Half","option3":null,"sku":"PCCLOXDBLU-H-XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - XL\/42 \/ Half","public_title":"XL\/42 \/ Half","options":["XL\/42","Half"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428538169,"title":"XXL\/44 \/ Full","option1":"XXL\/44","option2":"Full","option3":null,"sku":"PCCLOXDBLU-F-XXL","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - XXL\/44 \/ Full","public_title":"XXL\/44 \/ Full","options":["XXL\/44","Full"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428570937,"title":"XXL\/44 \/ Half","option1":"XXL\/44","option2":"Half","option3":null,"sku":"PCCLOXDBLU-H-XXL","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Dark Blue Colour Signature Shirt For Men - XXL\/44 \/ Half","public_title":"XXL\/44 \/ Half","options":["XXL\/44","Half"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428603705,"title":"3XL\/46 \/ Full","option1":"3XL\/46","option2":"Full","option3":null,"sku":"PCCLOXDBLU-F-3XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Dark Blue Colour Signature Shirt For Men - 3XL\/46 \/ Full","public_title":"3XL\/46 \/ Full","options":["3XL\/46","Full"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":51700428636473,"title":"3XL\/46 \/ Half","option1":"3XL\/46","option2":"Half","option3":null,"sku":"PCCLOXDBLU-H-3XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Dark Blue Colour Signature Shirt For Men - 3XL\/46 \/ Half","public_title":"3XL\/46 \/ Half","options":["3XL\/46","Half"],"price":134900,"weight":240,"compare_at_price":220000,"inventory_management":"shopify","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}}],"images":["\/\/myswadesi.in\/cdn\/shop\/files\/blue3.jpg?v=1770369009","\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-2071416.jpg?v=1770369009","\/\/myswadesi.in\/cdn\/shop\/files\/blue2.jpg?v=1768653479","\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-5784434.jpg?v=1770502928"],"featured_image":"\/\/myswadesi.in\/cdn\/shop\/files\/blue3.jpg?v=1770369009","options":["Size","Sleeves"],"media":[{"alt":null,"id":44439363354937,"position":1,"preview_image":{"aspect_ratio":1.0,"height":4032,"width":4032,"src":"\/\/myswadesi.in\/cdn\/shop\/files\/blue3.jpg?v=1770369009"},"aspect_ratio":1.0,"height":4032,"media_type":"image","src":"\/\/myswadesi.in\/cdn\/shop\/files\/blue3.jpg?v=1770369009","width":4032},{"alt":"Dark Blue Colour Signature Classic Oxford Shirt For Men - Punekar Cotton","id":44439363322169,"position":2,"preview_image":{"aspect_ratio":1.0,"height":2048,"width":2048,"src":"\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-2071416.jpg?v=1770369009"},"aspect_ratio":1.0,"height":2048,"media_type":"image","src":"\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-2071416.jpg?v=1770369009","width":2048},{"alt":null,"id":44439363289401,"position":3,"preview_image":{"aspect_ratio":1.0,"height":4032,"width":4032,"src":"\/\/myswadesi.in\/cdn\/shop\/files\/blue2.jpg?v=1768653479"},"aspect_ratio":1.0,"height":4032,"media_type":"image","src":"\/\/myswadesi.in\/cdn\/shop\/files\/blue2.jpg?v=1768653479","width":4032},{"alt":"Dark Blue Colour Signature Classic Oxford Shirt For Men - Punekar Cotton","id":44531132858681,"position":4,"preview_image":{"aspect_ratio":1.0,"height":2048,"width":2048,"src":"\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-5784434.jpg?v=1770502928"},"aspect_ratio":1.0,"height":2048,"media_type":"image","src":"\/\/myswadesi.in\/cdn\/shop\/files\/dark-blue-colour-signature-classic-oxford-shirt-for-men-5784434.jpg?v=1770502928","width":2048}],"requires_selling_plan":false,"selling_plan_groups":[],"content":"\u003cp\u003e\u003cmeta charset=\"utf-8\"\u003e\u003cstrong\u003eIntroducing our Signature Classic Oxford Shirt for Men. \u003c\/strong\u003eCrafted from premium cotton oxford fabric, this dark blue shirt delivers refined elegance with everyday practicality. The naturally breathable weave ensures all-day comfort, while the durable construction with stands regular wear and washing. Its versatile design transitions seamlessly from professional settings to casual occasions, making it an essential addition to any wardrobe. The flexible fabric drapes beautifully, offering both structure and ease of movement for the modern man who values quality and sophistication.\u003c\/p\u003e\n\u003cp class=\"selectable-text copyable-text x15bjb6t x1n2onr6\"\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eNeckline\u003c\/strong\u003e: Spread Collar\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eFabric\u003c\/strong\u003e: Cotton Oxford\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003eFit\u003c\/strong\u003e: Regular Fit\u003cbr\u003e\u003c\/span\u003e\u003cspan class=\"selectable-text copyable-text xkrh14z\"\u003e\u003cstrong\u003ePattern\u003c\/strong\u003e: Solid\u003cbr\u003e\u003c\/span\u003e\u003cstrong data-end=\"591\" data-start=\"581\"\u003eSleeve\u003c\/strong\u003e: Full \u0026amp; Half Sleeve\u003c\/p\u003e"},
enableRewardBadgeOnStorefront: null,
enableAltPayWithPoints: null,
};
window.ytapp = data;
} catch (error) {
console.error('Error in app-embed script:', error);
}
// create resource hints for the app's script CDN (dynamic origin)
try {
const scriptSrc = 'https://cdn.shopify.com/extensions/01a06e27-4758-7b62-80cd-6db2c8372ec8/yourtoken-2-1145/assets/index.js';
const scriptUrl = new URL(scriptSrc, window.location.href);
const origin = scriptUrl.origin;
// Add preconnect and dns-prefetch for app CDN if not already present
if (!document.querySelector(`link[rel="preconnect"][href="${origin}"]`)) {
const pc = document.createElement('link');
pc.rel = 'preconnect';
pc.href = origin;
pc.crossOrigin = '';
document.head.appendChild(pc);
}
if (!document.querySelector(`link[rel="dns-prefetch"][href="${origin}"]`)) {
const dp = document.createElement('link');
dp.rel = 'dns-prefetch';
dp.href = origin;
document.head.appendChild(dp);
}
// Preload the main script for early fetch
if (!document.querySelector(`link[rel="preload"][href="${scriptSrc}"]`)) {
const pl = document.createElement('link');
pl.rel = 'preload';
pl.as = 'script';
pl.href = scriptSrc;
pl.crossOrigin = '';
document.head.appendChild(pl);
}
// Create and append the script with high priority
const script = document.createElement('script');
script.src = scriptSrc;
script.fetchPriority = 'high';
script.crossOrigin = '';
script.defer = 'punekar-cotton.myshopify.com' === "robocraze-com.myshopify.com";
document.body.appendChild(script);
} catch (error) {
console.error('Error loading script:', error);
}
const style = document.createElement('link');
style.rel = 'stylesheet';
style.href = 'https://cdn.shopify.com/extensions/01a06e27-4758-7b62-80cd-6db2c8372ec8/yourtoken-2-1145/assets/index.css';
document.head.appendChild(style);
// Signal that initialization started (shell system handles cart protection now)
window.ytInitStarted = true;
}
} catch (error) {
console.error('Error initializing:', error);
}
}
initializeYourToken();