(function polyfill() {
const relList = document.createElement("link").relList;
if (relList && relList.supports && relList.supports("modulepreload")) {
return;
}
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) {
processPreload(link);
}
new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type !== "childList") {
continue;
}
for (const node of mutation.addedNodes) {
if (node.tagName === "LINK" && node.rel === "modulepreload")
processPreload(node);
}
}
}).observe(document, { childList: true, subtree: true });
function getFetchOpts(link) {
const fetchOpts = {};
if (link.integrity) fetchOpts.integrity = link.integrity;
if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
if (link.crossOrigin === "use-credentials")
fetchOpts.credentials = "include";
else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
else fetchOpts.credentials = "same-origin";
return fetchOpts;
}
function processPreload(link) {
if (link.ep)
return;
link.ep = true;
const fetchOpts = getFetchOpts(link);
fetch(link.href, fetchOpts);
}
})();
const orichiLimitGetVariants = () => {
return new Promise((resolve) => {
const cache = "?v=";
$.ajax({
url: "/cart.json" + cache,
type: "GET",
async: false,
dataType: "json",
success: (res) => {
resolve({
ProductID: res.items == void 0 ? [] : res.items.map((a) => a.product_id),
ProductTitle: res.items == void 0 ? [] : res.items.map((a) => a.product_title),
Variants: res.items == void 0 ? [] : res.items.map((a) => a.id),
Quantities: res.items == void 0 ? [] : res.items.map((a) => a.quantity),
Prices: res.items == void 0 ? [] : res.items.map((a) => a.price / 100),
OriginalPrices: res.items == void 0 ? [] : res.items.map((a) => a.original_price / 100),
FinalPrices: res.items == void 0 ? [] : res.items.map((a) => a.final_price / 100),
Grams: res.items == void 0 ? [] : res.items.map((a) => a.grams),
shopid: __st.a,
token: res.token,
shop: Shopify.shop,
customerEmail: $(".OrichiCustomerEmail").val(),
customerTags: $(".OrichiCustomerTags").val(),
DiscountShopify: res.cart_level_discount_applications,
Note: res.note == void 0 || res.note == null ? "" : res.note,
ListItems: res.items,
Totalprice: res.total_price / 100,
OriginalTotalprice: res.original_total_price / 100,
Attributes: Object.keys(res.attributes == null ? {} : res.attributes).map((key) => {
return key + "|||" + res.attributes[key];
}).join("???"),
Properties: (res.items == void 0 ? [] : res.items.map((a) => a.properties)).map(
(p) => Object.keys(p == null ? {} : p).map((key) => {
return key + "|||" + p[key];
}).join("???")
)
});
}
});
});
};
const parameter = () => {
var _a;
const parameters = ((_a = window.orichiLimit) == null ? void 0 : _a.parameters) ?? [];
const parameterCache = /* @__PURE__ */ new Map();
const findParameter = (key) => {
if (parameterCache.has(key)) {
return parameterCache.get(key);
}
const param = parameters.find((p) => p.Key === key);
parameterCache.set(key, param);
return param;
};
const getValue = (key) => {
var _a2;
return (_a2 = findParameter(key)) == null ? void 0 : _a2.Value;
};
const checkValue = (key, value) => {
var _a2;
return ((_a2 = findParameter(key)) == null ? void 0 : _a2.Value) === value;
};
const getValueIfMatches = (key, value) => {
const paramValue = getValue(key);
return paramValue === value ? paramValue : void 0;
};
return {
getValue,
checkValue,
getValueIfMatches
};
};
const initParameter = () => {
const { getValue } = parameter();
if (getValue("All-Css-Custom")) {
const styleElement = document.createElement("style");
styleElement.textContent = getValue("All-Css-Custom");
document.head.appendChild(styleElement);
}
if (getValue("All-Js-Custom")) {
const scriptElement = document.createElement("script");
scriptElement.textContent = getValue("All-Js-Custom");
document.head.appendChild(scriptElement);
}
};
const SELECTOR_CONFIG = [
{
key: "QUANTITY_INPUT",
append: "All_QUANTITY_INPUT_APPEND",
override: "All_QUANTITY_INPUT_OVR"
},
{
key: "ORICHI_BUTTON_IN_FORM_CART",
append: "All_BUTTON_IN_FORM_CART_APPEND",
override: "All_BUTTON_IN_FORM_CART_OVR"
},
{
key: "ORICHI_VARIANT_SELECTOR",
append: "All_VARIANT_SELECTOR_APPEND",
override: "All_VARIANT_SELECTOR_OVR"
},
{
key: "ORICHI_BUTTON_CHECKOUT",
append: "All_BUTTON_CHECKOUT_APPEND",
override: "All_BUTTON_CHECKOUT_OVR"
},
{
key: "ORICHI_BUTTON_PLUS_MINUS",
append: "All_BUTTON_PLUS_MINUS_APPEND",
override: "All_BUTTON_PLUS_MINUS_OVR"
},
{
key: "CART_REMOVE_BUTTON",
append: "All_REMOVE_BUTTON_APPEND",
override: "All_REMOVE_BUTTON_OVR"
},
{
key: "ORICHI_CART_POPUP_SELECTOR",
append: "All_CART_POPUP_SELECTOR_APPEND",
override: "All_CART_POPUP_SELECTOR_OVR"
},
{
key: "ORICHI_DISABLE_BUTTON_APP_IF_LIMITED",
append: "All_DISABLE_BUTTON_APP_IF_LIMITED_APPEND",
override: "All_DISABLE_BUTTON_APP_IF_LIMITED_OVR"
}
];
const overrideSelector = () => {
const { getValue } = parameter();
SELECTOR_CONFIG.forEach(({ key, append, override }) => {
const appendValue = getValue(append);
const overrideValue = getValue(override);
if (appendValue) {
SELECTOR_ELEMENT.appendSelector(key, appendValue);
}
if (overrideValue) {
SELECTOR_ELEMENT.setSelector(key, overrideValue);
}
});
};
const overrideApi = async (func) => {
let isProcessing = false;
let timeoutId = null;
const handleCartUpdate = () => {
if (isProcessing) return;
isProcessing = true;
if (timeoutId) clearTimeout(timeoutId);
timeoutId = setTimeout(async () => {
await func();
isProcessing = false;
}, 100);
};
try {
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(...args) {
this.addEventListener("loadend", function() {
if (this._url && this._url.search(/cart\/add|cart\/change/) >= 0 && this._method && this._method.toUpperCase() !== "GET") {
handleCartUpdate();
}
});
originalOpen.apply(this, args);
};
} catch (error) {
console.error("Error overriding XMLHttpRequest:", error);
}
try {
const originalFetch = fetch;
window.fetch = function(input, init) {
const isCartUpdate = typeof input.search === "function" && (input.search(/cart\/add|cart\/change/) >= 0 || input.search("/api/2023-07/graphql.json") >= 0) && input.search("ba_request") < 0;
const isPostOrPut = init && ["POST", "PUT"].includes((init.method || "").toUpperCase());
const response = originalFetch(input, init);
if (isCartUpdate && isPostOrPut) {
response.then(() => {
handleCartUpdate();
});
}
return response;
};
} catch (error) {
console.error("Error overriding fetch:", error);
}
if (typeof ShopifyAPI !== "undefined" && ShopifyAPI.changeItem && !ShopifyAPI.changeItem.toString().includes("func")) {
const originalChangeItem = ShopifyAPI.changeItem;
ShopifyAPI.changeItem = function(line, quantity, callback) {
originalChangeItem(line, quantity, (...args) => {
callback(...args);
handleCartUpdate();
});
};
}
};
const TargetEnum = {
CART: "cart",
PRODUCT: "product",
COLLECTION: "collection",
VARIANT: "variant",
PRODUCT_TAG: "product_tag"
};
const ValidationRuleEnum = {
MINIMUM_QUANTITY: "minimum_quantity",
MAXIMUM_QUANTITY: "maximum_quantity",
MINIMUM_VALUE: "minimum_value",
MAXIMUM_VALUE: "maximum_value",
SPECIFIC_QUANTITY: "specific_quantity",
MULTIPLES: "multiples"
};
const calculateTagQuantityOrValue = (currentLimit, fieldInCartJson) => {
const isFieldQuantity = fieldInCartJson === "quantity";
const productTagsInCart = window.orichiLimit.cart;
const cartItems = window.orichiLimit.cartItems;
const value = productTagsInCart.reduce((sum, itemInCartLiquid) => {
const matchingProduct = cartItems.ListItems.find(
(item) => item.product_id === itemInCartLiquid.productId
);
if (matchingProduct && itemInCartLiquid.tags.some((tag) => {
var _a;
return (_a = currentLimit == null ? void 0 : currentLimit.ProductTags) == null ? void 0 : _a.includes(tag);
})) {
return sum + (isFieldQuantity ? matchingProduct.quantity : matchingProduct.discounted_price * matchingProduct.quantity);
}
return sum;
}, 0);
return isFieldQuantity ? value : value / 100;
};
const html = String.raw;
const getMultiplesQuantity = (currentQuantity, value) => {
return currentQuantity % value === 0;
};
const wait = (time) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, time);
});
};
const removeDuplicateErrors = (errors) => {
return Array.from(new Set(errors.map(JSON.stringify))).map(JSON.parse);
};
const calculateValueInCart = () => {
const listItems = window.orichiLimit.cartItems.ListItems;
return listItems.reduce((sum, item) => sum + item.discounted_price * item.quantity, 0) / 100;
};
const validateRule = (rule, totalQuantity, currentLimit) => {
const totalQuantityTag = calculateTagQuantityOrValue(currentLimit, "quantity");
const totalTagValueInCart = calculateTagQuantityOrValue(currentLimit, "discounted_price");
const totalValueInCart = calculateValueInCart();
const { Type, Value } = rule;
const numericValue = parseFloat((Value * Number(window.Shopify.currency.rate)).toFixed(2));
const isTagTarget = currentLimit.Target === TargetEnum.PRODUCT_TAG;
const quantity = isTagTarget ? totalQuantityTag : totalQuantity;
const value = isTagTarget ? totalTagValueInCart : totalValueInCart;
switch (Type) {
case ValidationRuleEnum.MINIMUM_QUANTITY:
return quantity < numericValue ? { type: Type, value: Value } : null;
case ValidationRuleEnum.MAXIMUM_QUANTITY:
return quantity > numericValue ? { type: Type, value: Value } : null;
case ValidationRuleEnum.MINIMUM_VALUE:
return value < numericValue ? { type: Type, value: Value } : null;
case ValidationRuleEnum.MAXIMUM_VALUE:
return value > numericValue ? { type: Type, value: Value } : null;
case ValidationRuleEnum.MULTIPLES:
$(SELECTOR_ELEMENT.QUANTITY_INPUT).attr("step", numericValue);
return !getMultiplesQuantity(totalQuantity, numericValue) ? { type: Type, value: Value } : null;
case ValidationRuleEnum.SPECIFIC_QUANTITY:
return quantity !== numericValue ? { type: Type, value: Value } : null;
default:
return null;
}
};
const Validation = async ({ currentLimit, totalQuantity }) => {
if (!currentLimit) return;
const errors = currentLimit.ValidationRules.map(
(rule) => validateRule(rule, totalQuantity, currentLimit)
).filter((error) => error !== null).map((error) => {
var _a;
return {
...error,
messageCheckoutPage: ((_a = currentLimit.AlertMessages) == null ? void 0 : _a[0].Value) || ""
};
});
return { errors, currentLimit };
};
const findProductInLimit = (currentProductId, target) => {
var _a;
var limits = window.orichiLimit.limits;
let productTags = (_a = window.orichiLimit.currentProduct) == null ? void 0 : _a.tags;
const cartLiquid = window.orichiLimit.cart;
const productTagsInCart = cartLiquid.find(
(item) => item.productId === parseInt(currentProductId)
);
if (productTagsInCart && !productTags) {
productTags = productTagsInCart.tags;
}
if (window.Shopify.shop == "fluwelcom.myshopify.com" && limits) {
limits = limits.sort(
(a, b) => parseInt(a.ValidationRules[0].Value) - parseInt(b.ValidationRules[0].Value)
);
}
const targetProducts = limits.find(
(limit) => limit.ShopifyObjects.some((obj) => obj.Id === parseInt(currentProductId)) && limit.Status
);
if (target === TargetEnum.PRODUCT_TAG) {
const targetTags = limits.find(
(limit) => {
var _a2;
return ((_a2 = limit == null ? void 0 : limit.ProductTags) == null ? void 0 : _a2.some((tag) => productTags == null ? void 0 : productTags.includes(tag))) && limit.Status;
}
);
return targetProducts || targetTags;
}
return targetProducts;
};
const ModalError = (allErrors) => {
$("
", {
id: "error-modal",
html: html`
${allErrors == null ? void 0 : allErrors.map((error) => `- ${error.messageCheckoutPage}
`).join("")}
`
}).appendTo("body").hide();
};
const TEXT = {
ORDER_INVALID: "Order is not valid"
};
let buttonCheckoutInterval;
const handleButtonCheckout = (errors) => {
const buttonCheckout = $(SELECTOR_ELEMENT.ORICHI_BUTTON_CHECKOUT);
const existingCloneElement = $(".orichi-limit-modal-error");
if (errors.length > 0 && buttonCheckout.length && !existingCloneElement.length) {
const cloneElement = $("