(function() { var current_variant = ""; var theme_general_setting = { "cartPageSetting": { "cart_item_main_ele": " #mini-cart .mini-cart__line-item-list .mini-cart__line-item, .card .line-item-table tbody .line-item", "product_name_element": { "element": ".line-item__product-info .line-item__meta .line-item__title", "place_at": "after" }, "product_price_element": { "element": ".line-item__line-price span", "place_at": "after" }, "subtotal_element": { "element": "form[action='/cart'] .card .card__section .cart-recap__price-line, #mini-cart .mini-cart__recap .mini-cart__recap-price-line", "place_at": "after" } }, "quantity_click_ele": "form[action='/cart/add'] button[data-action='add-to-cart'], .quantity-selector .quantity-selector__button", "on_qty_change_set_timeout":500, "sidebar_open_ele": ".header__action-list .header__action-item--cart a[href='/cart']", "force_click_ele": "form[action='/cart/add'] button[data-action='add-to-cart'], a[data-action='decrease-quantity']", "on_force_click_set_timeout":1000, "show_cart_html_timeout":500, "cart_qty_change_ele" : ", input[aria-label='Quantity']" }; 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","minimum_selected_products_quantity_tier":"Minimum quantity of selected products( Same discount)","minimum_selected_products_value_tier":"Minimum value of selected products( Same discount)","discount_fixamount_column":"Discount","discount_percentage_column":"Discount","discount_price_3_column":"Discounted Price","table_footer_text":"Cart level discount will applied on cart page based on cart"}}; var css_setting = {"product_page":{"discount_title_color":"#ffffff","discount_title_font_size":"16","group_desciption_color":"#1e2d7d","group_description_font_size":"16","theader_bg_color":"#e6e6e6","theader_color":"#1e2d7d","theader_font_size":"18","tbody_bg_color":"#fff5f5","tbody_color":"#000000","tbody_font_size":"21","tborder_color":"#000000","tborder_width":"0","tborder_style":"Solid","tborder_radius":"5"},"cart_page":{"rxfc_cart_discount_class_css":".rxfc-discount-table{width: 100%; } .rxfc-cart-discount{text-align: left;} .rxfc-cart-discount .rxfc-cart-discount__price{text-align: right;float: right;}"}}; 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 `
`+ variant_avail_qty +` Quantity left for this product. Discount want be apply for this product.
`; } } } return ""; }, preapareProductDiscountHtmlTable: function(data){ var that = this; let discount_groups = data.discount_groups; let showtaxexcamtcol = data.showtaxexcamtcol; let thead_title_label = lang_label_setting.hasOwnProperty('ProductPageSetting') ? lang_label_setting.ProductPageSetting : {}; let product_page_setting = theme_general_setting.hasOwnProperty('ProductPageSetting') ? theme_general_setting.ProductPageSetting : {}; let wants_to_hide_title = product_page_setting.hasOwnProperty("wants_to_hide_title") ? product_page_setting.wants_to_hide_title : 'N'; let want_apl_dic_msg = ""; if(product_page_setting.hasOwnProperty("disp_want_aply_disc_qty_msg") && product_page_setting.disp_want_aply_disc_qty_msg == 'Y'){ want_apl_dic_msg = that.getWantAplDiscountMsg(data); } var discount_html_tables =`
` + want_apl_dic_msg +`
`; let table_footer_text = thead_title_label.hasOwnProperty('table_footer_text') ? thead_title_label.table_footer_text : ''; let product_tables = cart_tables = ''; $.each(discount_groups, function( key, discount_group) { let first_col_title = thead_title_label.hasOwnProperty('discount_title_color') ? thead_title_label.discount_title_color : discount_group.tier_title; let discount_2_column = 'Discount'; let discount_price_3_column = thead_title_label.hasOwnProperty('discount_price_3_column') ? thead_title_label.discount_price_3_column : 'Discounted Price'; let tax_discount_price_column = thead_title_label.hasOwnProperty('tax_discount_price_column') ? thead_title_label.tax_discount_price_column : 'Tax Excluded Discounted Price'; if(discount_group.tier_slug == 'minimum-line-item-quantity-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_line_item_quantity_tier') ? thead_title_label.minimum_line_item_quantity_tier : discount_group.tier_title; } if(discount_group.tier_slug == 'minimum-line-item-value-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_line_item_value_tier') ? thead_title_label.minimum_line_item_value_tier : discount_group.tier_title; } if(discount_group.tier_slug == 'minimum-cart-quantity-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_cart_quantity_tier') ? thead_title_label.minimum_cart_quantity_tier : discount_group.tier_title; } if(discount_group.tier_slug == 'minimum-cart-value-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_cart_value_tier') ? thead_title_label.minimum_cart_value_tier : discount_group.tier_title; } if(discount_group.tier_slug == 'minimum-selected-products-quantity-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_selected_products_quantity_tier') ? thead_title_label.minimum_selected_products_quantity_tier : discount_group.tier_title; } if(discount_group.tier_slug == 'minimum-selected-products-value-tier'){ first_col_title = thead_title_label.hasOwnProperty('minimum_selected_products_value_tier') ? thead_title_label.minimum_selected_products_value_tier : discount_group.tier_title; } if(discount_group.discount_type == 'percentage'){ discount_2_column = thead_title_label.hasOwnProperty('discount_percentage_column') ? thead_title_label.discount_percentage_column : 'Discount'; } if(discount_group.discount_type == 'amount'){ discount_2_column = thead_title_label.hasOwnProperty('discount_fixamount_column') ? thead_title_label.discount_fixamount_column : 'Discount'; } discount_html = `
`; if(wants_to_hide_title != 'Y'){ discount_html += `
` + discount_group.discount_title + `
`; } discount_html += ``; if(discount_group.discount_value_show == 'Y'){ discount_html += ``; } if(discount_group.discounted_price_show == 'Y'){ discount_html += ``; } if(showtaxexcamtcol == 'Y'){ discount_html += ``; } discount_html += ``; let currency_symbol = discount_group.currency_symbol; $.each(discount_group.tiers, function( t_key, tiers) { let tier_key = tiers.tier_key; let tier_value = tiers.tier_value; let product_discount = RxfcUtil.makePrice(tiers.product_discount, currency_symbol); let tax_exc_discount = RxfcUtil.makePrice(tiers.tax_exc_discount, currency_symbol); if(discount_group.tier_slug == 'minimum-line-item-value-tier'){ tier_key = RxfcUtil.makePrice(tier_key, currency_symbol); } if(discount_group.discount_type == 'amount'){ tier_value = RxfcUtil.makePrice(tier_value, currency_symbol); } discount_html += ``; if(discount_group.discount_value_show == 'Y'){ discount_html += ``; } if(discount_group.discounted_price_show == 'Y'){ discount_html += ``; } if(showtaxexcamtcol == 'Y'){ discount_html += ``; } discount_html += ``; }); discount_html += `
` + first_col_title + `` + discount_2_column + `` + discount_price_3_column + `` + tax_discount_price_column + `
` + tier_key + `+` + tier_value + `` + product_discount + `` + tax_exc_discount + `
`; if(discount_group.discount_desc != null){ discount_html += `
` + discount_group.discount_desc + `
`; } discount_html += `
`; if(discount_group.tier_slug == 'minimum-line-item-quantity-tier' || discount_group.tier_slug == 'minimum-line-item-value-tier'){ product_tables += discount_html; } else{ cart_tables += discount_html; } }); if(product_tables != '' && cart_tables != ''){ product_tables += '

'; } discount_html_tables += product_tables; discount_html_tables += cart_tables; if(cart_tables != '' && table_footer_text != '' && table_footer_text.length > 0){ discount_html_tables += ``; } discount_html_tables += `
`; return discount_html_tables; }, showDiscountTable: function(discount_html){ $("#rxfc-discount").remove(); var elementSelector = ''; var positioningFunction = 'after'; var formSelectors = GlobalFormSelectors; var custom_table_sel = (product_table_ele.hasOwnProperty("element") && $(""+ product_table_ele.element).length > 0) ? true : false; if(custom_table_sel === false){ for (var sel in formSelectors) { if (formSelectors.hasOwnProperty(sel)) { if ($(sel).length === 1) { elementSelector = sel; positioningFunction = formSelectors[sel]; break; } } } } else{ elementSelector = product_table_ele.element; positioningFunction = product_table_ele.place_at; } if (elementSelector !== '' && $(elementSelector).length === 1) { if (positioningFunction === 'prepend') { $(elementSelector).prepend(discount_html); } else if (positioningFunction === 'before') { $(elementSelector).before(discount_html); } else if (positioningFunction === 'after') { $(elementSelector).after(discount_html); } } }, fetchCart: async function(){ var that = this; let response_cart = undefined; $.ajax({ url: "/cart.js", async:false, dataType: "json", success:function(response){ response_cart = response; } }); return response_cart; }, ByeItDirectProduct: async function(){ var that = this; fetch('/cart/clear.js', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({})}) .then(response => { let current_variant = ($('input[name=id]').length > 0) ? $('input[name=id]').val() : $('select[name=id] option:selected').val(); let sel_quantity = ($('input[name=quantity]').length > 0 && parseInt($('input[name=quantity]').val()) > 0) ? parseInt($('input[name=quantity]').val()) : 1; let formData = {'items': [{'id': current_variant,'quantity': sel_quantity}]}; fetch('/cart/add.js', { method: 'POST',headers: {'Content-Type': 'application/json'}, body: JSON.stringify(formData) }) .then(response => { that.fetchCart().then(function(cart_json) { if(typeof cart_json != undefined) { that.createCheckout(cart_json, true); } }); }) .catch((error) => { console.error('Error:', error); }); }) .catch((error) => { console.error('Error:', error); }); }, createCheckout: async function(cart_data, redirect){ let customer_id = (meta.page.hasOwnProperty("customerId")) ? meta.page.customerId : ''; /* cart_data = JSON.stringify(cart_data); */ let currency = Shopify.currency; let return_data = undefined; let checkout_flag = 'No'; if(redirect == true){ checkout_flag = 'Yes'; } var form = new FormData($('form[action="/cart"]')[0]); var formData = Object.fromEntries(form.entries()); $.ajax({ url: "https://ws.rexific.com/shopify/create-checkout", type: 'POST', data: { shop:shop, cart:cart_data, customer_id: customer_id, currency: currency, checkout: checkout_flag, extra_params: JSON.stringify(formData) }, dataType:"json", async:false, headers:{ "Access-Control-Allow-Origin":"*", "Access-Control-Allow-Methods":"*", "Access-Control-Allow-Headers":"*" }, success:function(response) { if(typeof response != undefined && response.hasOwnProperty("success") == true) { if(response.success == 1 && response.hasOwnProperty("data") == true){ let data = (response.hasOwnProperty("data") == true) ? response.data : ''; if(checkout_flag != 'Yes'){ return_data = data; } if( data != '' && ((data.hasOwnProperty('checkout') && data.checkout.hasOwnProperty('web_url')) || (data.hasOwnProperty('draft_order') && data.draft_order.hasOwnProperty('invoice_url')))) { let web_url = ''; if(data.hasOwnProperty('checkout')){ web_url = data.checkout.web_url; } else{ web_url = data.draft_order.invoice_url; } if(redirect == true && web_url != ''){ if(checkout_click_timeout != "" && parseInt(checkout_click_timeout) > 0){ let time_n = parseInt(checkout_click_timeout); setTimeout(function(){ window.location.href = web_url; },time_n); } else{ window.location.href = web_url; } return false; } return_data = data; } normal_checkout = true; } else{ normal_checkout = true; } if(normal_checkout == true && checkout_flag == 'Yes'){ window.location.href = window.location.origin + '/checkout'; return false } } } }); return return_data; }, showCartPageHtml : function () { var that = this; $(".rxfc-cart-discount").remove(); $(".rxfc-discout-title").remove(); $(".rxfc-discout-price").remove(); that.fetchCart().then(function(cart_json) { if(typeof cart_json != undefined) { that.createCheckout(cart_json, false).then(function(data) { that.prepairAndRenderCartHtml(data); setTimeout(function(){ if(show_cart_html_timeout != "" && parseInt(show_cart_html_timeout) > 0 && $(".rxfc-cart-discount").length == 0){ that.prepairAndRenderCartHtml(data); } }, show_cart_html_timeout); }); } }); }, prepairAndRenderCartHtml : function(data){ if(typeof data != "undefined") { let currency_symbol = data.currency_symbol; let applied_item_discounts = data.applied_item_discount; let cart_discount = data.total_discount; let subtotal_price = data.subtotal_price; let line_items = data.cart.items; let cart_after_discout_price = data.cart_after_discout_price; if((parseFloat(subtotal_price) >= 0) || parseFloat(cart_discount) > 0){ if(cart_discount > 0){ if(typeof theme_general_setting == "object" && theme_general_setting.hasOwnProperty("cartPageSetting") && theme_general_setting.cartPageSetting.hasOwnProperty("sticky_subtotal_element")){ let sticky_subtotal_element = theme_general_setting.cartPageSetting.sticky_subtotal_element; if(sticky_subtotal_element != ""){ let stricky_html = ``+ RxfcUtil.makePrice(cart_after_discout_price, currency_symbol) + ``; $(""+ sticky_subtotal_element.element).first().css("text-decoration", "line-through").after(stricky_html); } } if(typeof theme_general_setting == "object" && theme_general_setting.hasOwnProperty("cartPageSetting") && theme_general_setting.cartPageSetting.hasOwnProperty("cart_item_main_ele") && $( "" + theme_general_setting.cartPageSetting.cart_item_main_ele ).length > 0){ let cartPageSetting = theme_general_setting.cartPageSetting; let cart_item_main_ele = (cartPageSetting.hasOwnProperty("cart_item_main_ele")) ? cartPageSetting.cart_item_main_ele : ""; let product_name_element = (cartPageSetting.hasOwnProperty("product_name_element")) ? cartPageSetting.product_name_element : ""; /* let cart_item_qty_ele = (cartPageSetting.hasOwnProperty("cart_item_qty_ele")) ? cartPageSetting.cart_item_qty_ele : "";*/ let product_price_element = (cartPageSetting.hasOwnProperty("product_price_element")) ? cartPageSetting.product_price_element : ""; /* let cart_total_item_price_ele = (cartPageSetting.hasOwnProperty("cart_total_item_price_ele")) ? cartPageSetting.cart_total_item_price_ele : ""; */ let subtotal_element = (cartPageSetting.hasOwnProperty("subtotal_element")) ? cartPageSetting.subtotal_element : ""; let aft_disc_price = (cartPageSetting.hasOwnProperty("aft_disc_price")) ? cartPageSetting.aft_disc_price : ""; // bellow 3 fieleds use to hide cart level auto discount let hide_cart_level_auto_discount = (cartPageSetting.hasOwnProperty("hide_cart_level_auto_discount")) ? cartPageSetting.hide_cart_level_auto_discount : "No"; let hide_cart_discount_ele = (cartPageSetting.hasOwnProperty("hide_cart_discount_ele")) ? cartPageSetting.hide_cart_discount_ele : ""; let cart_subtotal_amount_ele = (cartPageSetting.hasOwnProperty("cart_subtotal_amount_ele")) ? cartPageSetting.cart_subtotal_amount_ele : ""; // bellow field use to hide & uncheck original line price let hide_cart_item_discount_lable_ele = (cartPageSetting.hasOwnProperty("hide_cart_item_discount_lable_ele")) ? cartPageSetting.hide_cart_item_discount_lable_ele : ""; let cart_item_price_ele = (cartPageSetting.hasOwnProperty("cart_item_price_ele")) ? cartPageSetting.cart_item_price_ele : ""; if(typeof applied_item_discounts == "object" && Object.keys(applied_item_discounts).length > 0 && line_items.length > 0){ $.each(line_items, function(item_key, line_item){ $.each(applied_item_discounts, function(disk_key, applied_item_discount){ let product_detail = "
" + lbl_item_discount_title + " "+ applied_item_discount.discount_title +"
"; let cart__final_price = "
"+ RxfcUtil.makePrice(applied_item_discount.discouted_price,currency_symbol) +"
"; if(line_item.product_id == applied_item_discount.product_id && line_item.variant_id == applied_item_discount.variant_id && line_item.quantity == applied_item_discount.quantity){ if(product_name_element != ""){ let product_ele = $(cart_item_main_ele + ":eq( "+ item_key +" )").find(""+product_name_element.element); if(product_name_element.place_at == 'after'){ $(product_ele).after(product_detail); }else { $(product_ele).parent().after(product_detail); } } if(product_price_element != ""){ $(cart_item_main_ele + ":eq( "+ item_key +" )").find(""+product_price_element.element).last().css("text-decoration", "line-through").after(cart__final_price); } } }); }); let html = `
` + lbl_total_discount + ` `+ RxfcUtil.makePrice(cart_discount, currency_symbol) + `
` + lbl_after_discount_total + ` `+ RxfcUtil.makePrice(cart_after_discout_price, currency_symbol) + `
`; if(subtotal_element != ""){ $(""+ subtotal_element.element).show().after(html); } if(aft_disc_price != ""){ let aft_disc_price_html = RxfcUtil.makePrice(cart_after_discout_price, currency_symbol); $(""+ aft_disc_price).first().html(""+ aft_disc_price_html); } // bellow condition use to hide cart level auto discount if(hide_cart_level_auto_discount == 'Yes'){ $(hide_cart_item_discount_lable_ele).attr("style", "display:none !important;"); $(cart_item_price_ele).attr("style", "text-decoration: none !important;"); $(hide_cart_discount_ele).attr("style", "display:none !important;"); $sub_total_amt = RxfcUtil.makePrice(subtotal_price, currency_symbol); $(cart_subtotal_amount_ele).html($sub_total_amt); } } } else { let productCnt = {}; $.each(line_items, function(item_key, line_item){ if(productCnt[line_item.product_id] === undefined) { productCnt[line_item.product_id] = 0; } else { productCnt[line_item.product_id] = productCnt[line_item.product_id] + 1; } if(applied_item_discounts[line_item.product_id+"-"+item_key] !== undefined) { let item = applied_item_discounts[line_item.product_id+"-"+item_key]; let product_detail = "
"+ lbl_item_discount_title + ""+ item.discount_title +"
"; let cart__final_price = "
"+ RxfcUtil.makePrice(item.discouted_price, currency_symbol) +"
"; var count = 0; let thisElement = $("form[action*='/cart'] a:contains('" + item.title.replace(/'/g, "\\'") + "'), form[action*='/cart'] a:contains('" + item.product_title.replace(/'/g, "\\'") + "')")[productCnt[line_item.product_id]]; if(typeof thisElement == "object"){ let title = $(thisElement).html().trim(); if(title == item.product_title || title == item.title){ if($(thisElement).parent().children().length > 1){ $(thisElement).parent().find('.rxfc-discout-title').remove(); $(thisElement).after(product_detail); }else { $(thisElement).parent().parent().find('.rxfc-discout-title').remove(); $(thisElement).parent().after(product_detail); } $(thisElement).parents().each(function(index){ price_thousant_saperator = item.final_line_price; let price_cnt = $(this).find(":contains("+ RxfcUtil.makePrice(item.final_line_price, currency_symbol) +")").length; let price_cnt_saperated = $(this).find(":contains("+ RxfcUtil.makePrice(price_thousant_saperator, currency_symbol) +")").length; if((price_cnt > 0 || price_cnt_saperated > 0 ) && count == 0){ let price_ele = $(this).find(":contains("+RxfcUtil.makePrice(item.final_line_price, currency_symbol)+")").last(); if(price_ele.length == 0){ price_ele = $(this).find(":contains("+ RxfcUtil.makePrice(price_thousant_saperator, currency_symbol)+")").last(); cart__final_price = "
"+ RxfcUtil.makePrice(item.discouted_price, currency_symbol) +"
"; } $(price_ele).parent().find('.rxfc-discout-price').remove(); $(price_ele).css("text-decoration", "line-through").after(cart__final_price); count = 1; return false; } }); } } } }); let html = `
` + lbl_total_discount + ` `+ RxfcUtil.makePrice(cart_discount, currency_symbol) + `
` + lbl_after_discount_total + ` `+ RxfcUtil.makePrice(cart_after_discout_price, currency_symbol) + `
`; if($('form[action="/cart"] .cart-subtotal').length > 0){ let child_count = $('form[action="/cart"] .cart-subtotal').children().length; if($('form[action="/cart"] .cart-subtotal').prop("tagName") == 'TR' && child_count > 0){ html = `` + html + ``; } $('form[action="/cart"] .cart-subtotal').after(html); $('form[action="/cart"] .cart-subtotal').show(); }else { $(':regex(class,^.*(cart.+subtotal)|(subtotal).*$)').last().parent().after(html); /* $(':regex(class,^.*(cart.+subtotal)|(subtotal).*$)').last().html(total_line_items_price); */ $(':regex(class,^.*(cart.+subtotal)|(subtotal).*$)').last().show(); } } } } } }, checkAndDisplayDiscountInPopup: function(){ var that = this; setInterval(function(){ if((($(""+cart_checkout_popup_ele).length > 0 && $(""+cart_checkout_popup_ele).hasClass("" + popup_ele_show_hide_class)) || (typeof ajaxifyShopify == 'object' && $("#ajaxifyModal").hasClass('is-visible'))) && cart_popup_closed == true){ that.showCartPageHtml(); cart_popup_closed = false; } }, 1000); setInterval(function(){ if((($(""+cart_checkout_popup_ele).length > 0 && $(""+cart_checkout_popup_ele).hasClass("" + popup_ele_show_hide_class) == false) || (typeof ajaxifyShopify == 'object' && $("#ajaxifyModal").hasClass('is-visible') == false)) && cart_popup_closed == false){ cart_popup_closed = true; } }, 1000); }, getDiscountTablePreview: async function(preview){ var that = this; let response_cart = undefined; let customer_id = (meta.page.hasOwnProperty("customerId") == true) ? meta.page.customerId : ''; let currency = Shopify.currency; let product_id = ShopifyAnalytics.meta.product.id; $.ajax({ url: "https://ws.rexific.com/shopify/preview-discount-table", type: 'POST', data: { shop:shop, preview:preview, customer_id: customer_id, currency: currency, product_id: product_id }, dataType:"json", async:false, headers:{ "Access-Control-Allow-Origin":"*", "Access-Control-Allow-Methods":"*", "Access-Control-Allow-Headers":"*" }, success:function(response){ if(typeof response != undefined && response.hasOwnProperty("success") == true) { if(response.success == 1 && response.hasOwnProperty("data") == true) { let data = (response.hasOwnProperty("data") == true) ? response.data : ''; if(data != '' && data.hasOwnProperty('preview_table')) { var preview_table = data.preview_table; var discount_html = that.preapareProductDiscountHtmlTable(preview_table); if(discount_html != ""){ that.showDiscountTable(discount_html) } } } } } }); return response_cart; } }; wholesale.init(); }; /* call the function... */ var css_without_important = (theme_general_setting.hasOwnProperty("css_without_important")) ? theme_general_setting.css_without_important : 'N'; var customStyle = "https://ws.rexific.com/modules/shopify/css/wholesale.css"; if(css_without_important == 'Y'){ customStyle = "https://ws.rexific.com/modules/shopify/css/wholesale_imp.css"; } loadStyle(customStyle); if (typeof $ === 'undefined') { script_js = 'https://code.jquery.com/jquery-3.4.1.min.js'; loadScript(script_js,rxfcMain); } else { rxfcMain(); } })();