(function() { var current_variant = ""; var theme_general_setting = {}; var lang_label_setting = {"ProductPageSetting":{"minimum_line_item_quantity_tier":"Quantity","minimum_line_item_value_tier":"Minimum line item value","minimum_cart_quantity_tier":"Minimum cart total quantity","minimum_cart_value_tier":"Minimum cart total value","discount_fixamount_column":"Discount","discount_percentage_column":"Discount","discount_price_3_column":"Discounted Price"}}; var css_setting = {"product_page":{"discount_title_color":"#000000","discount_title_font_size":"20","group_desciption_color":"#333232","group_description_font_size":"14","theader_bg_color":"#d7d5d5","theader_color":"#000000","theader_font_size":"14","tbody_bg_color":"#fff5f5","tbody_color":"#000000","tbody_font_size":"14","tborder_color":"#000000","tborder_width":"2","tborder_style":"Solid","tborder_radius":"5"}}; var loadScript = function(url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { script.onload = function() { callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; var loadStyle = function(url) { var style = document.createElement("link"); if (style.readyState) { style.onreadystatechange = function() { if (style.readyState == "loaded" || style.readyState == "complete") { style.onreadystatechange = null; } }; } else { style.onload = function() { }; } style.rel = 'stylesheet'; style.type = 'text/css'; style.href = url; document.getElementsByTagName("head")[0].appendChild(style); }; var rxfcMain = function() { var checkProductPage = meta.page.pageType; var shop = Shopify.shop; var RxfcUtil = (function() { var nav = { getPageName: function() { var path = window.location.pathname; var pageName = path.substring(path.lastIndexOf("/") + 1); return pageName; }, isProductPage: function() { if (checkProductPage != undefined && checkProductPage == "product") { return true; } return false; }, isHomePage: function() { if (checkProductPage != undefined && checkProductPage == "home") { return true; } return false; }, getProductHandler: function() { var path = window.location.pathname; var productHandle = path.substring(path.lastIndexOf("/") + 1); return productHandle; }, getHomeProductHandle: function() { var href = window.location.href; href = href.replace('/products/products', '/products'); if (/\/products\/([^\?\/\n]+)/.test(href)) { var found = href.match(/\/products\/([^\?\/\n]+)/); if (typeof found[1] !== 'undefined') { try { return decodeURIComponent(found[1]); } catch (e) { return found[1]; } } } return false; } }; var ShopifyAjaxCall = { getProductData: function(productHandle) { var productData = false; $.ajax({ url: `/products/${productHandle}.js`, type: 'GET', dataType: 'json', async: false, success: function(data) { productData = data; }, error: function(req, err) { console.log(error); } }); return productData; } }; var makePrice = function(amount, symbol){ amount = amount.toString().replace(",", ''); if(amount == '' || parseFloat(amount) == 0){ return "$0.00"; } var price_format = (theme_general_setting.hasOwnProperty("price_format")) ? theme_general_setting.price_format : ''; if(price_format != ''){ price_amount = parseFloat(amount).toLocaleString(price_format, {minimumFractionDigits: 2,maximumFractionDigits: 2}); } else{ price_amount = parseFloat(amount).toFixed(2); } if(typeof symbol != 'undefined'){ price_amount = symbol + price_amount; } else{ price_amount = price_amount + ' ' + Shopify.currency.active; } return price_amount; }; return { nav: nav, ShopifyAjaxCall: ShopifyAjaxCall, makePrice:makePrice }; })(); $.expr[':'].regex = function(elem, index, match) { var matchParams = match[3].split(','), validLabels = /^(data|css):/, attr = { method: matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr', property: matchParams.shift().replace(validLabels,'') }, regexFlags = 'ig', regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags); return regex.test($(elem)[attr.method](attr.property)); }; var GlobalFormSelectors = { 'form[action="/cart/add"] .product-form': 'after', 'form.product-form--wide[action="/cart/add"]': 'prepend', 'form.shopify-product-form[action="/cart/add"] .desc_blk .main-product-description-product': 'before', 'form[action="/cart/add"].ProductForm': 'prepend', 'form[action="/cart/add"] div.item-content div[data-icon="gpicon-product-quantity"]': 'before', 'form.pf-product-form[action="/cart/add"][id^="product_form_"] div[data-product-type="price"][data-pf-type="ProductText"]': 'after', 'form#AddToCartForm.form-vertical[action="/cart/add"].product-form .product-title': 'after', 'form[action="/cart/add"]': 'after', 'form[action="/cart/add"]': 'after', 'form.product-form[action="/cart/add"]': 'after', /* in form[action*="/cart/add"] is there to match actions on translated product pages, where action is /nl/cart/add */ 'form[action*="/cart/add"]': 'prepend', 'form.shopify-product-form[action="/cart/add"]': 'prepend', '.product_section form[action="/cart/add"]': 'prepend', 'form[action="/cart/add"] #product-content .quantity': 'before', 'form[action="/cart/add"] .shop-product__description .product-variant-option': 'before', 'form.AddToCartForm[action="/cart/add"] .item-content .module-wrap[data-icon="gpicon-product-swatches"]': 'before', 'form.formAddToCart[action="/cart/add"] div.proVariants': 'before', 'form[action="/cart/add"] .selector-wrapper.product-form__item': 'before', 'form[action="/cart/add"].product-form': 'prepend', 'form[action="/cart/add"].product-single__form': 'prepend', 'form[action="/cart/add"][id^="AddToCartForm--"]': 'prepend', 'form#cart-form[action="/cart/add"]': 'prepend', 'form#form_buy[action="/cart/add"]': 'prepend', 'form.product-form[action$="/cart/add"]': 'prepend', 'form#AddToCartForm.product-content-inner[action="/cart/add"] .product-details-text .product-variant-option': 'before', 'form#AddToCartForm.product-content-inner[action="/cart/add"] .product-description': 'before', 'form.shopify-product-form[action="/cart/add.js"]': 'prepend', '[itemtype="http://schema.org/Offer"] form[action="/cart/add"][data-productid]': 'prepend', '#shopify-section-product-template form[action="/cart/add"]': 'prepend', '[data-product-form] form.productForm[action="/cart/add"]': 'prepend', 'form#AddToCartForm[action*="/cart/add"]': 'prepend', '[data-pf-type="Section"] form.pf-product-form[action="/cart/add"][id^="product_form_"]': 'prepend', 'form#add-to-cart-form': 'prepend', '[itemtype="http://schema.org/Offer"] form[action*="/cart/add"].product-action.addProduct': 'prepend', 'form[action="/cart/add"].product-form:not(.cart-bar__form)': 'prepend', 'form[action="/cart/add"].product-form:not(.cart-bar__form):visible .product__submit.product__submit--spb': 'before', '#shopify-section-static-product form.product-form': 'prepend', '#AddToCartForm_id': 'prepend', 'form[data-cart-submit="data-cart-submit"][data-productid]': 'prepend', '[data-section="product-template"] form.shopify-product-form': 'prepend', 'form[action="/cart"].cart-subtotal': 'after', '.product-form form[action="/cart/add"]': 'prepend', '.product-form form[action="/cart/add"]': 'after' }; /* cart page language labels */ var lbl_item_discount_title = (lang_label_setting.hasOwnProperty("lbl_item_discount_title")) ? lang_label_setting.lbl_item_discount_title : "Discount:"; var lbl_total_discount = (lang_label_setting.hasOwnProperty("lbl_item_discount_title")) ? lang_label_setting.lbl_total_discount : "Discount"; var lbl_after_discount_total = (lang_label_setting.hasOwnProperty("lbl_after_discount_total")) ? lang_label_setting.lbl_after_discount_total : "After Discount Total"; var clon_checkout_button = (theme_general_setting.hasOwnProperty("clon_checkout_button") && theme_general_setting.clon_checkout_button == 'Yes') ? theme_general_setting.clon_checkout_button : "No"; var has_cart_checkout_popup = (theme_general_setting.hasOwnProperty("has_cart_checkout_popup") && theme_general_setting.has_cart_checkout_popup == 'Yes') ? theme_general_setting.has_cart_checkout_popup : "No"; var cart_checkout_popup_ele = (theme_general_setting.hasOwnProperty("cart_checkout_popup_ele") && theme_general_setting.cart_checkout_popup_ele != '') ? theme_general_setting.cart_checkout_popup_ele : ""; var popup_ele_show_hide_class = (theme_general_setting.hasOwnProperty("popup_ele_show_hide_class") && theme_general_setting.popup_ele_show_hide_class != '') ? theme_general_setting.popup_ele_show_hide_class : ""; var quantity_click_ele = (theme_general_setting.hasOwnProperty("quantity_click_ele") && theme_general_setting.quantity_click_ele != '') ? theme_general_setting.quantity_click_ele : ""; var checkout_click_timeout = (theme_general_setting.hasOwnProperty("on_checkout_click_set_timeout") && theme_general_setting.quantity_click_ele != '') ? theme_general_setting.on_checkout_click_set_timeout : ""; var product_page_css = (css_setting.hasOwnProperty("product_page")) ? css_setting.product_page : undefined; var product_table_ele = (theme_general_setting.hasOwnProperty("product_table_ele")) ? theme_general_setting.product_table_ele : {}; var qty_change_set_timeout = (theme_general_setting.hasOwnProperty("on_qty_change_set_timeout") && theme_general_setting.on_qty_change_set_timeout != '') ? theme_general_setting.on_qty_change_set_timeout : ""; var show_cart_html_timeout = (theme_general_setting.hasOwnProperty("show_cart_html_timeout") && theme_general_setting.show_cart_html_timeout != '') ? theme_general_setting.show_cart_html_timeout : ""; var force_click_ele = (theme_general_setting.hasOwnProperty("force_click_ele") && theme_general_setting.force_click_ele != '') ? theme_general_setting.force_click_ele : ""; var on_force_click_set_timeout = (theme_general_setting.hasOwnProperty("on_force_click_set_timeout") && theme_general_setting.on_force_click_set_timeout != '') ? theme_general_setting.on_force_click_set_timeout : ""; var cart_qty_change_ele = (theme_general_setting.hasOwnProperty("cart_qty_change_ele") && theme_general_setting.cart_qty_change_ele != '') ? theme_general_setting.cart_qty_change_ele : ""; var force_click_checkout_ele = (theme_general_setting.hasOwnProperty("force_click_checkout_ele") && theme_general_setting.force_click_checkout_ele != '') ? theme_general_setting.force_click_checkout_ele : ""; var cart_popup_closed = true; var wholesale = { init:function() { var that = this; $(document).ready(function(event) { if(clon_checkout_button == 'Yes' && $("input[name='checkout'], button[name='checkout']").length > 0){ $("input[name='checkout'], button[name='checkout']").each(function(){ $(this).clone() .attr('type', 'button').attr('id', 'rxfc_checkout_btn').attr('name', 'rxfc_checkout_btn').insertAfter(this); $(this).remove(); }); } if (RxfcUtil.nav.isProductPage()) { that.setProductPageCssStyle(); var preview = that.checkPreviewSet(); if(typeof preview == 'undefined') { setInterval(function() { let new_variant = (new URL(window.location)).searchParams.get('variant'); let prod_variant_ids = ShopifyAnalytics.meta.product.variants.map(variant => variant.id); if(typeof new_variant != 'string' || new_variant == "" && prod_variant_ids.length > 0) { new_variant_i = ($('input[name=id]').length > 0) ? $('input[name=id]').val() : ''; new_variant_s = ($('select[name=id] option:selected').length > 0) ? $('select[name=id] option:selected').val() : ''; if(new_variant_i != '' && prod_variant_ids.includes(parseInt(new_variant_i))) { new_variant = new_variant_i; } else if(new_variant_s != '' && prod_variant_ids.includes(parseInt(new_variant_s))) { new_variant = new_variant_s; } else if(current_variant == ""){ new_variant = prod_variant_ids[0]; } } if(current_variant != new_variant) { current_variant = new_variant; that.fetchProductDiscount(); } }, 200); if($("input[data-testid='Checkout-button'], button[data-testid='Checkout-button']").length > 0) { let btn = $("input[data-testid='Checkout-button'], button[data-testid='Checkout-button']").get(0); btn.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); that.ByeItDirectProduct(); }, true); } } else{ $("input[type='button'],input[type='submit'], button").attr("disabled", true); that.getDiscountTablePreview(preview); } } let cartPageSetting = (theme_general_setting.hasOwnProperty("cartPageSetting")) ? theme_general_setting.cartPageSetting : {}; let cart_chk_parent_chng_ele = (cartPageSetting.hasOwnProperty("cart_chk_parent_chng_ele")) ? cartPageSetting.cart_chk_parent_chng_ele : undefined; let cart_chk_btn = (cartPageSetting.hasOwnProperty("cart_chk_btn")) ? cartPageSetting.cart_chk_btn : undefined; if(typeof cart_chk_parent_chng_ele == 'string' && cart_chk_parent_chng_ele != ''){ $(cart_chk_parent_chng_ele).html(''); $(cart_chk_parent_chng_ele).html(cart_chk_btn); $('.rx-ws-checkout').on("click",function(e) { $('.rx-ws-checkout').addClass("revy-button-loading-state"); /* e.preventDefault(); e.stopPropagation(); */ that.fetchCart().then(function(cart_json) { if(typeof cart_json != undefined) { that.createCheckout(cart_json, true); } }); }); } $(document).on('click', "input[name='checkout'], button[name='checkout'], a[href='/checkout'], input[name='rxfc_checkout_btn'],button[data-translate='cart.general.checkout']", function(e) { e.preventDefault(); e.stopPropagation(); that.fetchCart().then(function(cart_json) { if(typeof cart_json != undefined) { that.createCheckout(cart_json, true); } }); }); $(document).on("change","form[action^='/cart'] input[name='updates[]'], form[action^='/cart'] input[id^=quantity_], form[action^='/cart'] input[id^=updates_large_]" + cart_qty_change_ele, function(){ $('form[action="/cart"] .cart-subtotal').hide(); $(".rxfc-cart-discount").hide(); $(".rxfc-discout-title").remove(); $(".rxfc-discout-price").remove(); setTimeout(function(){ that.showCartPageHtml(); }, 1000); }); if(quantity_click_ele != ""){ $(document).on("click","" + quantity_click_ele, function(){ /* $('form[action="/cart"] .cart-subtotal').hide(); $(".rxfc-cart-discount").hide(); $(".rxfc-discout-title").remove(); $(".rxfc-discout-price").remove(); */ var settime_n = 5000; if(qty_change_set_timeout != "" && parseInt(qty_change_set_timeout) > 0){ settime_n = parseInt(qty_change_set_timeout); } setTimeout(function(){ that.showCartPageHtml(); }, settime_n); }); } if(force_click_ele != ""){ let clickSelectors = [ force_click_ele ]; document.addEventListener('click', function (event) { for (let selector of clickSelectors) { let elements = document.querySelectorAll(selector); for (let element of elements) { if (element.isSameNode(event.target)) { var settime_n = 20; if(on_force_click_set_timeout != "" && parseInt(on_force_click_set_timeout) > 0){ settime_n = parseInt(on_force_click_set_timeout); } setTimeout(function(){ that.showCartPageHtml(); }, settime_n); } } } }, true); } if(force_click_checkout_ele != ""){ let clickCartSelectors = [ force_click_checkout_ele ]; document.addEventListener('click', function (event) { for (let selector of clickCartSelectors) { let elements = document.querySelectorAll(selector); for (let element of elements) { if (element.isSameNode(event.target)) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); that.fetchCart().then(function(cart_json) { if(typeof cart_json != undefined) { that.createCheckout(cart_json, true); } }); } } } }, true); } if((has_cart_checkout_popup == 'Yes' && cart_checkout_popup_ele != '') || (typeof ajaxifyShopify == 'object' && ($("a[href='/cart'].cart-toggle").length > 0))) { that.checkAndDisplayDiscountInPopup(); } else { that.showCartPageHtml(); } if(typeof theme_general_setting == "object" && theme_general_setting.hasOwnProperty("sidebar_open_ele")){ let sidebar_open_ele = theme_general_setting.sidebar_open_ele; $(document).on("click","" + sidebar_open_ele, function(){ that.showCartPageHtml(); }); } }); that.addCss(); }, addCss:function(){ var cart_page_css = (css_setting.hasOwnProperty("cart_page")) ? css_setting.cart_page : {}; let style = ``; $('head').append(style); }, checkPreviewSet: function(){ var that = this; try { let params = (new URL(window.location)).searchParams; let discount_param = params.get('preview'); if(typeof discount_param === "string" && discount_param.length > 0) { return discount_param } return undefined; } catch(err) { console.log("code not found..."); } return false; }, setProductPageCssStyle: function(){ var that = this; try { if(typeof product_page_css == "undefined" && product_page_css.length == 0) { return false; } let discount_title_color = product_page_css.hasOwnProperty('discount_title_color') ? product_page_css.discount_title_color : ''; let discount_title_font_size = product_page_css.hasOwnProperty('discount_title_font_size') ? product_page_css.discount_title_font_size : ''; let group_desciption_color = product_page_css.hasOwnProperty('group_desciption_color') ? product_page_css.group_desciption_color : ''; let group_description_font_size = product_page_css.hasOwnProperty('group_description_font_size') ? product_page_css.group_description_font_size : ''; let theader_bg_color = product_page_css.hasOwnProperty('theader_bg_color') ? product_page_css.theader_bg_color : ''; let theader_color = product_page_css.hasOwnProperty('theader_color') ? product_page_css.theader_color : ''; let tbody_bg_color = product_page_css.hasOwnProperty('tbody_bg_color') ? product_page_css.tbody_bg_color : ''; let tbody_color = product_page_css.hasOwnProperty('tbody_color') ? product_page_css.tbody_color : ''; let tborder_color = product_page_css.hasOwnProperty('tborder_color') ? product_page_css.tborder_color : ''; let theader_font_size = product_page_css.hasOwnProperty('theader_font_size') ? product_page_css.theader_font_size : ''; let tbody_font_size = product_page_css.hasOwnProperty('tbody_font_size') ? product_page_css.tbody_font_size : ''; let tborder_width = product_page_css.hasOwnProperty('tborder_width') ? product_page_css.tborder_width : ''; let tborder_style = product_page_css.hasOwnProperty('tborder_style') ? product_page_css.tborder_style : ''; let tborder_radius = product_page_css.hasOwnProperty('tborder_radius') ? product_page_css.tborder_radius : ''; var product_page_css_str = ``; $("head").append(product_page_css_str); } catch(err) { console.log("code not found..."); } return false; }, fetchProductDiscount: function(){ var that = this; let product_data = meta.product; let customer_id = (meta.page.hasOwnProperty("customerId") == true) ? meta.page.customerId : ''; let currency = Shopify.currency; if(current_variant == undefined || current_variant == ""){ return false; } $.ajax({ url: "https://ws.rexific.com/shopify/fetch-product-discounts", type: 'POST', data: { shop: shop, product_data: product_data, customer_id: customer_id, variant: current_variant, currency: currency }, dataType:"json", headers:{ "Access-Control-Allow-Origin":"*", "Access-Control-Allow-Methods":"*", "Access-Control-Allow-Headers":"*" }, success:function(response){ if(response.hasOwnProperty("success") == true && response.success == 1){ var discount_html = that.preapareProductDiscountHtmlTable(response.data); if(discount_html != ""){ that.showDiscountTable(discount_html) } } } }); }, getWantAplDiscountMsg: function(data){ let variants_avail_qty = (data.hasOwnProperty("variants_avail_qty")) ? data.variants_avail_qty : {}; let min_discount_qty = (data.hasOwnProperty("min_discount_qty")) ? data.min_discount_qty : 0; let variants_avail_qty_ids = Object.keys(variants_avail_qty); if(parseInt(min_discount_qty) > 0 && variants_avail_qty_ids.length > 0){ let sel_variant = ($('input[name=id]').length > 0) ? $('input[name=id]').val() : $('select[name=id] option:selected').val(); if(variants_avail_qty_ids.includes(sel_variant)){ let variant_avail_qty = variants_avail_qty[sel_variant]; if(parseInt(variant_avail_qty) < min_discount_qty){ return `
` + first_col_title + ` | `; if(discount_group.discount_value_show == 'Y'){ discount_html += `` + discount_2_column + ` | `; } if(discount_group.discounted_price_show == 'Y'){ discount_html += `` + discount_price_3_column + ` | `; } if(showtaxexcamtcol == 'Y'){ discount_html += `` + tax_discount_price_column + ` | `; } discount_html += `
---|---|---|---|
` + tier_key + `+ | `; if(discount_group.discount_value_show == 'Y'){ discount_html += `` + tier_value + ` | `; } if(discount_group.discounted_price_show == 'Y'){ discount_html += `` + product_discount + ` | `; } if(showtaxexcamtcol == 'Y'){ discount_html += `` + tax_exc_discount + ` | `; } discount_html += `