const TAG = 'spz-custom-utils'; const DEFAULT_DELAY_TIME = 100; class SpzCustomUtils extends SPZ.BaseElement { constructor(element) { super(element); this.templates_ = SPZServices.templatesForDoc(); } buildCallback() { this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); this.xhr_ = SPZServices.xhrFor(this.win); } static deferredMount() { return false; } mountCallback() { } //判断是否为移动端 isMobile() { /* 判断机型与处理 */ const u = navigator.userAgent const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端 const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端 return (isAndroid || isiOS); }; /** * url query param to object * @param {string} url * @returns {object} query object */ params(url) { url = url || window.location.href; let params = {}; url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) { try { params[key] = decodeURIComponent(value); } catch (e) { params[key] = value; } }); return params; }; /** * @param fn {Function} 实际要执行的函数 * @param delay {Number} 延迟时间,单位是毫秒(ms) * @return {Function} 返回一个“防反跳”了的函数 */ debounce(fn, delay) { // 定时器,用来 setTimeout let timer; // 返回一个函数,这个函数会在一个时间区间结束后的 delay 毫秒时执行 fn 函数 return function () { // 保存函数调用时的上下文和参数,传递给 fn const context = this; const args = arguments; // 每次这个返回的函数被调用,就清除定时器,以保证不执行 fn clearTimeout(timer); // 当返回的函数被最后一次调用后(也就是用户停止了某个连续的操作), // 再过 delay 毫秒就执行 fn timer = setTimeout(function () { fn.apply(context, args); }, delay); }; }; /* 节流防抖 */ throttle(func, wait, mustRun) { var timeout, startTime = new Date(); return function () { var context = this, args = arguments, curTime = new Date(); clearTimeout(timeout); // 如果达到了规定的触发时间间隔,触发 handler if (mustRun && curTime - startTime >= mustRun) { func.apply(context, args); startTime = curTime; // 没达到触发间隔,重新设定定时器 } else { timeout = setTimeout(func, wait); } }; }; //滚动加载方法 isToPageEnd(id) { const $el = document.querySelector(`[data-section-id='${id}']`); const scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop; //滚动条距离顶部的高度 const clientHeight = window.innerHeight; //当前可视的页面高度 const scrollHeight = document.body.scrollHeight; //当前页面的总高度 const elOffsetTop = $el.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop; // 元素距离文档顶部距离 // 如果改卡片下面还有卡片或者dom,计算滚动加载需要考虑这个高度 const toBottom = scrollHeight - ($el.offsetHeight + elOffsetTop); //元素到浏览器底部的高度 if (scrollTop + clientHeight + toBottom + 100 >= scrollHeight) { return true; } return false; }; /** * url 添加前缀 * @param {string} path , 必须是前面有斜杠前缀的路径 * @returns string */ prefixionPath(prefix,urlPath) { if(typeof prefix !== 'string') return ; if(typeof urlPath !== 'string') return ; if(urlPath.indexOf('/') !== 0){ throw new Error('prefixPath: urlPath must be start with /'); } if(prefix.indexOf('/') !== 0){ throw new Error('prefixPath: prefix must be start with /'); } return prefix+urlPath; } /** * @param {string} urlPath * @returns {string} * @example globalizePath('/path_a/path_b')// => '/en/path_a/path_b' */ globalizePath(urlPath) { if(typeof urlPath !== 'string') return ; if(urlPath.indexOf('/') !== 0){ urlPath = '/'+urlPath; } let prefix = ((SHOPLAZZA && SHOPLAZZA.routes && SHOPLAZZA.routes.root) || ''); if(prefix.length>0){ if(prefix.indexOf('/') !== 0){ prefix = '/'+prefix; } return this.prefixionPath(prefix,urlPath); }else{ return urlPath; } } image_padding_bottom(width, height, origin) { origin = origin || 'limit'; if (width && height) { const hw_ratio = height / width; if (origin == 'limit') { if (hw_ratio < 0.62) { return '62%'; } else if (hw_ratio > 1.6) { return '160%'; } } return parseInt(hw_ratio * 100) + '%'; } return '100%'; } getNumber(str) { str = str + ''; return str.match(/\d+(\.\d+)?/g) ? Number(str.match(/\d+(\.\d+)?/g)[0]) : str; }; // 处理货币符号 finance_money_with_shop_symbol(price, onlyNumber) { const symbol = onlyNumber ? '' : window.SHOPLAZZA.currency_symbol; const position = window.SHOPLAZZA ? window.SHOPLAZZA.currency_symbol_pos : 'left'; const format = window.SHOPLAZZA ? window.SHOPLAZZA.money_format : 'amount'; if (position == 'right') { return Number(Number(price) * 1).format(format) + symbol; } return symbol + Number(Number(price) * 1).format(format); }; triggerEvent_(name, data) { const event = SPZUtils.Event.create(this.win, `${TAG}.${name}`, data || {}); this.action_.trigger(this.element, name, event); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomUtils) const TAG = 'spz-custom-lang-script'; class SpzCustomlangScript extends SPZ.BaseElement { constructor(element) { super(element); this.currentLangMap = null; } buildCallback() { this.getLang(); } getLang() { const i18nJSON = { 'en-US': { "start_in_text": "Start in", "end_in_text": "End in", "add_to_cart_successfully": "Added successfully", "view_cart": "View Cart", "add": "Add", "product": "Products", "modal_discount_tip": "Add {count} items for discount", "sold_out": "Sold Out", }, 'zh-CN': { "start_in_text": "距开始", "end_in_text": "距结束", "add_to_cart_successfully": "添加成功", "view_cart": "查看购物车", "add": "添加", "product": "个商品", "modal_discount_tip": "添加{count}件商品享受优惠", "sold_out": "已售罄", }, } const lang = sessionStorage._language || document.documentElement.lang || "en-US"; const currentLangMap = i18nJSON[lang] ? i18nJSON[lang] : i18nJSON["en-US"]; this.currentLangMap = currentLangMap; return currentLangMap; } getLangValue({ langKey }) { let currentLangMap = this.currentLangMap || this.getLang(); let langValue = currentLangMap[langKey]; return langValue; } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomlangScript) const TAG = 'spz-custom-lang'; class SpzCustomLang extends SPZ.BaseElement { constructor(element) { super(element); this.langKey = ""; this.count = ""; this.templates_ = SPZServices.templatesForDoc(); } static deferredMount() { return false; } buildCallback() { this.langKey = this.element.getAttribute('langKey'); this.count = this.element.getAttribute('count'); } mountCallback() { const render = async () => { const tempElement = document.getElementById('spz-custom-lang-script'); SPZ.whenApiDefined(tempElement).then(async (api) => { let lang_value = await api.getLangValue({langKey: this.langKey }); if (this.count) { lang_value = lang_value.replace("{count}", this.count); } var spanDom = document.createElement("div"); spanDom.innerHTML = lang_value; this.element.innerHTML = ""; this.element.appendChild(spanDom); }); }; this.mutateElement(render); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomLang) const TAG = 'spz-custom-sort'; class SpzCustomSort extends SPZ.BaseElement { constructor(element) { super(element); this.spz_custom_id = ''; } static deferredMount() { return false; } buildCallback() { this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); this.xhr_ = SPZServices.xhrFor(this.win); this.setupAction_(); } init() { this.bindEvent(); } bindEvent() { const $selectList = SPZCore.Dom.scopedQuerySelectorAll( this.element, ".sort_custom_content li" ); const $customerSelect = SPZCore.Dom.scopedQuerySelector( this.element, ".sort_custom_select" ); // 选择下拉选项 Array.from($selectList).forEach((node) => { SPZUtils.Event.listen(node, 'click', ()=> { let value = node.getAttribute('value'); let text = node.getAttribute('text'); // 触发selectChange 事件 this.triggerEvent_('selectChange', { value: value, name: value }) $customerSelect.innerHTML = text; const panelChilds = this.element.querySelectorAll(".sort_custom_panel li"); // 清空其他选项的勾选状态 Array.from(panelChilds).forEach((el) => { if(el.getAttribute('value') == value) { el.classList.add("active") } else { el.classList.remove('active'); } }) }); }) } // 渲染界面 async doRender_(data) { // 操作该组件的dom id this.spz_custom_id = data.id; return this.templates_ .findAndRenderTemplate(this.element, data) .then((el) => { const children = this.element.querySelector('*:not(template)'); children && SPZCore.Dom.removeElement(children); this.element.appendChild(el); }).then(() => { this.init(); }); } setupAction_() { this.registerAction('render', async(invocation) => { const data = invocation.args.data; this.doRender_(data) }); this.registerAction('handleSelect', async(invocation) => { const data = invocation.args.data; }); this.registerAction('handleDropdownOpen', async(invocation) => { const $selectDropDown = SPZCore.Dom.scopedQuerySelector( this.element, ".select_drop_down" ); $selectDropDown.classList.add('select_drop_down_rotate'); }); this.registerAction('handleDropdownClose', async(invocation) => { const $selectDropDown = SPZCore.Dom.scopedQuerySelector( this.element, ".select_drop_down" ); $selectDropDown.classList.remove('select_drop_down_rotate'); }); } triggerEvent_(name, data) { const event = SPZUtils.Event.create(this.win, `${ TAG }.${ name }`, data || {}); this.action_.trigger(this.element, name, event); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomSort) const TAG = "spz-custom-render-products"; class SpzCustomProducts extends SPZ.BaseElement { constructor(element) { super(element); } buildCallback() { this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); this.xhr_ = SPZServices.xhrFor(this.win); this.setupAction_(); } doRender_(data) { return this.templates_ .findAndRenderTemplate(this.element, data) .then((el) => { const children = this.element.querySelector('*:not(template)'); children && SPZCore.Dom.removeElement(children); this.element.appendChild(el); }); } getRenderTemplate(data) { const renderData = data || {}; return this.templates_ .findAndRenderTemplate(this.element, renderData) .then((el) => { const children = this.element.querySelector('*:not(template)'); children && SPZCore.Dom.removeElement(children); return el; }); } setupAction_() { this.registerAction('test', (invocation) => { }); } triggerEvent_(name, data) { const event = SPZUtils.Event.create(this.win, `${ TAG }.${ name }`, data || {}); this.action_.trigger(this.element, name, event); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomProducts) const TAG = 'spz-custom-discount-default'; const E_DISCOUNT_PROGRESS = { ProgressFinished : "PROGRESS_FINISHED", ProgressNotStarted : "PROGRESS_NOT_STARTED", ProgressOngoing : "PROGRESS_ONGOING" }; class SpzCustomDiscountDefault extends SPZ.BaseElement { constructor(element) { super(element); this.templates_ = null; let discountDefaultData = {"discount_info":{"id":"440768910216670761","center_id":"1199785","discount_name":"BOGO 50% OFF","display_name":"BOGO 50% OFF","discount_target":"DTT_PRODUCT","discount_type":"DT_BUY_ONE_GET_ONE","discount_method":"DM_AUTOMATIC","discount_code":"","starts_at":1730451599,"ends_at":1732784399,"progress":"PROGRESS_FINISHED","discount_layer":{"condition_type":"CT_PURCHASE_QUANTITY","obtain_type":"OT_PERCENT","layers":[{"condition_value":"1","obtain_count":1,"obtain_value":"50","condition_max_value":"-1"}],"layer_type":"LT_SIGNLE"},"starts_remaining_seconds":0,"ends_remaining_seconds":0,"enable_min_purchase_qty":false,"min_purchase_qty_type":""},"landing_page_info":{"customer":{"is_entitled_customer":false},"banner":{"text":"","config":"{\"color\":{\"banner_bg_start\":\"rgba(255, 136, 26, 1)\",\"banner_bg_end\":\"rgba(241, 48, 83, 1)\",\"banner_text\":\"rgba(255, 255, 255, 1)\",\"countdown_text\":\"rgba(34, 34, 34, 1)\",\"countdown_bg\":\"rgba(255, 246, 219, 1)\"},\"countdown\":{\"start_opened\":true,\"start_format\":\"DD:HH:mm:ss:SSS\",\"end_opened\":true,\"end_format\":\"DD:HH:mm:ss:SSS\"}}"},"poster":{"config":"{\"desktop\":\"\",\"mobile\":\"\",\"image_render\":\"fill\"}"},"additional":{"text":"","config":"{\"text_opened\":false,\"color\":{\"background\":\"rgba(230, 230, 230, 1)\",\"text\":\"rgba(34, 34, 34, 1)\"}}"},"product":{"buy_product":{"text":""},"obtain_product":{"text":""}},"sort":{"by":"title","direction":"asc"},"price_text_config":{"text":"","config":""},"button":{"text":"","config":"","redirect_page":""}},"buy_product_info":{"page":1,"has_more":true,"product":[{"id":"fc0ea870-dda7-4434-9ceb-8f8de5f9e758","title":"Absorbable Calcium with Vitamin D3","brief":"","vendor":"CAPTEK SOFTGEL INTERNATIONAL","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"absorbable-calcium-with-vitamin-d3","spu":"6274","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"21.99","price_max":"21.99","price":"21.99","compare_at_price":"21.99","compare_at_price_min":"21.99","compare_at_price_max":"21.99","url":"\/products\/absorbable-calcium-with-vitamin-d3","sales":"614","image":{"src":"\/\/img.staticdj.com\/7fbd3cb4e93e5644f750cc976c0ab45e.jpeg","alt":"","path":"7fbd3cb4e93e5644f750cc976c0ab45e.jpeg","width":2000,"height":2000},"variants":[{"id":"0bc54638-cb1d-4ace-b833-df85f2a4e1d2","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"6274","barcode":"191069762746","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"21.99","price":"21.99","available":false,"url":"\/products\/absorbable-calcium-with-vitamin-d3?variant=0bc54638-cb1d-4ace-b833-df85f2a4e1d2","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/7fbd3cb4e93e5644f750cc976c0ab45e.jpeg","alt":"","path":"7fbd3cb4e93e5644f750cc976c0ab45e.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/ce6048784bd16ef0c045e79467f1e76c.jpeg","alt":"","path":"ce6048784bd16ef0c045e79467f1e76c.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/ad2ffd4159b2a4b443b44178c481d2b3.jpg","alt":"","path":"ad2ffd4159b2a4b443b44178c481d2b3.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"de63f15b-36dc-4580-a1df-e71aa88671a0","title":"Acetyl L-Carnitine 1000 mg.","brief":"","vendor":"ADH HEALTH PRODUCTS","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"acetyl-l-carnitine-1000-mg","spu":"13796","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"39.99","price_max":"39.99","price":"39.99","compare_at_price":"39.99","compare_at_price_min":"39.99","compare_at_price_max":"39.99","url":"\/products\/acetyl-l-carnitine-1000-mg","sales":"27","image":{"src":"\/\/img.staticdj.com\/4af6f542c0c6b89d8b2635d07a46b255.jpeg","alt":"","path":"4af6f542c0c6b89d8b2635d07a46b255.jpeg","width":2000,"height":2000},"variants":[{"id":"a6943b5f-c8d1-42a1-a7ab-b2d757a60f39","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"13796","barcode":"191069137964","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"39.99","price":"39.99","available":false,"url":"\/products\/acetyl-l-carnitine-1000-mg?variant=a6943b5f-c8d1-42a1-a7ab-b2d757a60f39","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/4af6f542c0c6b89d8b2635d07a46b255.jpeg","alt":"","path":"4af6f542c0c6b89d8b2635d07a46b255.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/2897ef7b7292f0525a8cf0c4f86a94ad.jpeg","alt":"","path":"2897ef7b7292f0525a8cf0c4f86a94ad.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"db5bb636-aed9-4849-b279-2aa07397c59f","title":"Advanced Colon Cleanser","brief":"","vendor":"ADH HEALTH PRODUCTS","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"advanced-colon-cleanser","spu":"14817","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"26.99","price_max":"26.99","price":"26.99","compare_at_price":"26.99","compare_at_price_min":"26.99","compare_at_price_max":"26.99","url":"\/products\/advanced-colon-cleanser","sales":"702","image":{"src":"\/\/img.staticdj.com\/fa311dd6fc2f3287d4c294fd8bcec088.jpeg","alt":"","path":"fa311dd6fc2f3287d4c294fd8bcec088.jpeg","width":2000,"height":2000},"variants":[{"id":"e4cf1f2a-8f1c-40b8-a728-7ab84a1d3e47","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"14817","barcode":"191069148175","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"26.99","price":"26.99","available":false,"url":"\/products\/advanced-colon-cleanser?variant=e4cf1f2a-8f1c-40b8-a728-7ab84a1d3e47","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/fa311dd6fc2f3287d4c294fd8bcec088.jpeg","alt":"","path":"fa311dd6fc2f3287d4c294fd8bcec088.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/c635bb0080cf523da17d04bf44ef3a1b.jpg","alt":"","path":"c635bb0080cf523da17d04bf44ef3a1b.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"bdf345ef-0680-4f4c-abb0-3abedcb30dd3","title":"Advanced Prostate Formula Saw Palmetto Complex","brief":"","vendor":"ROBINSON PHARMA","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"215","inventory_tracking":true,"published":true,"handle":"advanced-prostate-formula-saw-palmetto-complex","spu":"6052","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"49.99","price_max":"49.99","price":"49.99","compare_at_price":"49.99","compare_at_price_min":"49.99","compare_at_price_max":"49.99","url":"\/products\/advanced-prostate-formula-saw-palmetto-complex","sales":"1051","image":{"src":"\/\/img.staticdj.com\/21db94761a3f269ddc833ea781f7d479.jpeg","alt":"","path":"21db94761a3f269ddc833ea781f7d479.jpeg","width":2000,"height":2000},"variants":[{"id":"a788d5d8-aee7-4fea-9901-ff05b6a9cfb9","title":"","weight_unit":"lb","inventory_quantity":"215","sku":"6052","barcode":"191069760520","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"49.99","price":"49.99","available":true,"url":"\/products\/advanced-prostate-formula-saw-palmetto-complex?variant=a788d5d8-aee7-4fea-9901-ff05b6a9cfb9","available_quantity":"215","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/21db94761a3f269ddc833ea781f7d479.jpeg","alt":"","path":"21db94761a3f269ddc833ea781f7d479.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/50c971b797733ad48ff567936d29e920.jpg","alt":"","path":"50c971b797733ad48ff567936d29e920.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"def3ab82-47fa-4009-beb7-52c9dadb99dc","title":"Advanced Sleep Complex 100 Rapid Release Capsules","brief":"","vendor":"AMERICA'S BEST NUTRITION","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"12","inventory_tracking":true,"published":true,"handle":"advanced-sleep-complex-100-rapid-release-softgels","spu":"99643","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"13.99","price_max":"13.99","price":"13.99","compare_at_price":"13.99","compare_at_price_min":"13.99","compare_at_price_max":"13.99","url":"\/products\/advanced-sleep-complex-100-rapid-release-softgels","sales":"415","image":{"src":"\/\/img.staticdj.com\/fec1f0c09a8ce74dc0da461c8f6a91b1.jpeg","alt":"","path":"fec1f0c09a8ce74dc0da461c8f6a91b1.jpeg","width":2000,"height":2000},"variants":[{"id":"f86ae2ba-5272-4957-97ee-21e739b8504a","title":"","weight_unit":"lb","inventory_quantity":"12","sku":"99643","barcode":"191069996431","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"13.99","price":"13.99","available":true,"url":"\/products\/advanced-sleep-complex-100-rapid-release-softgels?variant=f86ae2ba-5272-4957-97ee-21e739b8504a","available_quantity":"12","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/fec1f0c09a8ce74dc0da461c8f6a91b1.jpeg","alt":"","path":"fec1f0c09a8ce74dc0da461c8f6a91b1.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/f555d378a575dd099b89fb6d44194b89.jpg","alt":"","path":"f555d378a575dd099b89fb6d44194b89.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"e91ebbad-cd8a-4dfa-bc90-55fda96f6714","title":"Advanced Vision Formula with Lutein 200ct","brief":"","vendor":"ROBINSON PHARMA, INC","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"advanced-vision-formula-with-lutein-200ct","spu":"99554","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"31.99","price_max":"31.99","price":"31.99","compare_at_price":"31.99","compare_at_price_min":"31.99","compare_at_price_max":"31.99","url":"\/products\/advanced-vision-formula-with-lutein-200ct","sales":"115","image":{"src":"\/\/img.staticdj.com\/cff07f66ddd131a1b64600f1e6d1293b.jpeg","alt":"","path":"cff07f66ddd131a1b64600f1e6d1293b.jpeg","width":2000,"height":2000},"variants":[{"id":"7d34473b-e303-43b7-9110-aeff6ce3a713","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"99554","barcode":"191069995540","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"31.99","price":"31.99","available":false,"url":"\/products\/advanced-vision-formula-with-lutein-200ct?variant=7d34473b-e303-43b7-9110-aeff6ce3a713","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/cff07f66ddd131a1b64600f1e6d1293b.jpeg","alt":"","path":"cff07f66ddd131a1b64600f1e6d1293b.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/042becb7ec178b00f5d55b1ced80d106.jpeg","alt":"","path":"042becb7ec178b00f5d55b1ced80d106.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"a70f189f-00ae-4566-9e14-6f1685a046fe","title":"Alpha Lipoic 600MG Rapid Release Capsules","brief":"","vendor":"AMERICA'S BEST NUTRITION","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"alpha-lipoic-600mg-rapid-release-capsules","spu":"99748","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"29.99","price_max":"29.99","price":"29.99","compare_at_price":"29.99","compare_at_price_min":"29.99","compare_at_price_max":"29.99","url":"\/products\/alpha-lipoic-600mg-rapid-release-capsules","sales":"265","image":{"src":"\/\/img.staticdj.com\/f98a19002449373bd779e5b2ee2dabea.jpeg","alt":"","path":"f98a19002449373bd779e5b2ee2dabea.jpeg","width":2000,"height":2000},"variants":[{"id":"b54d1041-bf57-4721-9d1f-2c66f746276e","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"99748","barcode":"191069997483","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"29.99","price":"29.99","available":false,"url":"\/products\/alpha-lipoic-600mg-rapid-release-capsules?variant=b54d1041-bf57-4721-9d1f-2c66f746276e","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/f98a19002449373bd779e5b2ee2dabea.jpeg","alt":"","path":"f98a19002449373bd779e5b2ee2dabea.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/453e9e3eadd0edf6f4f4bcace1523a8e.jpg","alt":"","path":"453e9e3eadd0edf6f4f4bcace1523a8e.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"1e886e67-f08c-4bfe-a7fc-36e92168dce6","title":"Alpha Lipoic Acid 300 mg.","brief":"","vendor":"ROBINSON PHARMA","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"305","inventory_tracking":true,"published":true,"handle":"alpha-lipoic-acid-300-mg","spu":"13578","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"38.99","price_max":"38.99","price":"38.99","compare_at_price":"38.99","compare_at_price_min":"38.99","compare_at_price_max":"38.99","url":"\/products\/alpha-lipoic-acid-300-mg","sales":"286","image":{"src":"\/\/img.staticdj.com\/b01a245e071ed805e75f6b558aefddab.jpg","alt":"","path":"b01a245e071ed805e75f6b558aefddab.jpg","width":2000,"height":2000},"variants":[{"id":"b4c22afa-1994-4226-9003-c425ef982cef","title":"","weight_unit":"lb","inventory_quantity":"305","sku":"13578","barcode":"191069135786","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"38.99","price":"38.99","available":true,"url":"\/products\/alpha-lipoic-acid-300-mg?variant=b4c22afa-1994-4226-9003-c425ef982cef","available_quantity":"305","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/b01a245e071ed805e75f6b558aefddab.jpg","alt":"","path":"b01a245e071ed805e75f6b558aefddab.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/e7c432bff8e01cfcf3b910806cdce99a.jpg","alt":"","path":"e7c432bff8e01cfcf3b910806cdce99a.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"cacb72ff-bce5-489a-a279-a30021d7bfd6","title":"Apple Cider Vinegar 600MG","brief":"","vendor":"ROBINSON PHARMA","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"155","inventory_tracking":true,"published":true,"handle":"apple-cider-vinegar-600-mg","spu":"55667","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"19.99","price_max":"19.99","price":"19.99","compare_at_price":"19.99","compare_at_price_min":"19.99","compare_at_price_max":"19.99","url":"\/products\/apple-cider-vinegar-600-mg","sales":"117","image":{"src":"\/\/img.staticdj.com\/2941d6cc0758647f98ceed59ef568cfa.jpg","alt":"","path":"2941d6cc0758647f98ceed59ef568cfa.jpg","width":2000,"height":2000},"variants":[{"id":"13b976c3-36cf-43ec-be99-3560fa4b6722","title":"","weight_unit":"lb","inventory_quantity":"155","sku":"55667","barcode":"191069556673","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"19.99","price":"19.99","available":true,"url":"\/products\/apple-cider-vinegar-600-mg?variant=13b976c3-36cf-43ec-be99-3560fa4b6722","available_quantity":"155","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/2941d6cc0758647f98ceed59ef568cfa.jpg","alt":"","path":"2941d6cc0758647f98ceed59ef568cfa.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/bbb7fb236c0ee7ef09585d093271c40a.jpg","alt":"","path":"bbb7fb236c0ee7ef09585d093271c40a.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"770aa7d0-104c-4488-9a07-0d382daf051c","title":"Ashwagandha 500 mg.","brief":"","vendor":"AMERICA'S BEST NUTRITION","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"214","inventory_tracking":true,"published":true,"handle":"ashwagandha-500-mg","spu":"51433","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"18.99","price_max":"18.99","price":"18.99","compare_at_price":"18.99","compare_at_price_min":"18.99","compare_at_price_max":"18.99","url":"\/products\/ashwagandha-500-mg","sales":"117","image":{"src":"\/\/img.staticdj.com\/e7d25ad5a8d5f63b26dc66d095474ea6.webp","alt":"","path":"e7d25ad5a8d5f63b26dc66d095474ea6.webp","width":2000,"height":2000},"variants":[{"id":"72ebc774-aa70-4d17-abef-c7e30b87d8e8","title":"","weight_unit":"lb","inventory_quantity":"214","sku":"51433","barcode":"191069514338","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"18.99","price":"18.99","available":true,"url":"\/products\/ashwagandha-500-mg?variant=72ebc774-aa70-4d17-abef-c7e30b87d8e8","available_quantity":"214","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/e7d25ad5a8d5f63b26dc66d095474ea6.webp","alt":"","path":"e7d25ad5a8d5f63b26dc66d095474ea6.webp","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/16244e5eb0c37ea019ef8b2189e9e606.webp","alt":"","path":"16244e5eb0c37ea019ef8b2189e9e606.webp","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/fed4aa97da9814ee577c1d39eafaecb1.webp","alt":"","path":"fed4aa97da9814ee577c1d39eafaecb1.webp","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"8ffb7488-06f8-4462-a98f-492a52c59648","title":"B-Complex","brief":"","vendor":"ROBINSON PHARMA","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"264","inventory_tracking":true,"published":true,"handle":"b-complex","spu":"10283","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"39.99","price_max":"39.99","price":"39.99","compare_at_price":"39.99","compare_at_price_min":"39.99","compare_at_price_max":"39.99","url":"\/products\/b-complex","sales":"312","image":{"src":"\/\/img.staticdj.com\/1a8e34855b9cf3926aee9e47e3c331fe.jpeg","alt":"","path":"1a8e34855b9cf3926aee9e47e3c331fe.jpeg","width":2000,"height":2000},"variants":[{"id":"317ba9a7-4c64-4f30-8a5c-92dc6eaea681","title":"","weight_unit":"lb","inventory_quantity":"264","sku":"10283","barcode":"191069102832","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"39.99","price":"39.99","available":true,"url":"\/products\/b-complex?variant=317ba9a7-4c64-4f30-8a5c-92dc6eaea681","available_quantity":"264","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/1a8e34855b9cf3926aee9e47e3c331fe.jpeg","alt":"","path":"1a8e34855b9cf3926aee9e47e3c331fe.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/0bde6940e15a3259f89463803762a46e.jpeg","alt":"","path":"0bde6940e15a3259f89463803762a46e.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/0d97a3b2994a66a30b6d397f0925823c.jpeg","alt":"","path":"0d97a3b2994a66a30b6d397f0925823c.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"8656f9f5-202f-45df-b90d-a64c200d8df7","title":"Bee Propolis","brief":"","vendor":"CONTRACT PHARMACAL CORP.","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"3","inventory_tracking":true,"published":true,"handle":"bee-propolis","spu":"99756","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"23.99","price_max":"23.99","price":"23.99","compare_at_price":"23.99","compare_at_price_min":"23.99","compare_at_price_max":"23.99","url":"\/products\/bee-propolis","sales":"215","image":{"src":"\/\/img.staticdj.com\/43c06c088cdd3a8c1c68fed8e6ee1d97.jpeg","alt":"","path":"43c06c088cdd3a8c1c68fed8e6ee1d97.jpeg","width":2000,"height":2000},"variants":[{"id":"4e2549d3-0117-4e00-a23f-792b98c2b1b6","title":"","weight_unit":"lb","inventory_quantity":"3","sku":"99756","barcode":"191069997568","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"23.99","price":"23.99","available":true,"url":"\/products\/bee-propolis?variant=4e2549d3-0117-4e00-a23f-792b98c2b1b6","available_quantity":"3","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/43c06c088cdd3a8c1c68fed8e6ee1d97.jpeg","alt":"","path":"43c06c088cdd3a8c1c68fed8e6ee1d97.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/51bf7128af816b7c06bf4f137618efb4.jpeg","alt":"","path":"51bf7128af816b7c06bf4f137618efb4.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"e40c8bbc-a03f-4c01-84bf-5f67d0b1342f","title":"beets+ Gummies, Beet Root 1200MG, Antioxidant, Cardiovascular Support","brief":"","vendor":"PHARMVISTA GUMMY","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"151","inventory_tracking":true,"published":true,"handle":"beets-gummies-beet-root-1200mg-antioxidant-cardiovascular-support","spu":"99805","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"16.99","price_max":"16.99","price":"16.99","compare_at_price":"16.99","compare_at_price_min":"16.99","compare_at_price_max":"16.99","url":"\/products\/beets-gummies-beet-root-1200mg-antioxidant-cardiovascular-support","sales":"217","image":{"src":"\/\/img.staticdj.com\/274fcaad6a38941f3801971fbe735ca4.jpeg","alt":"","path":"274fcaad6a38941f3801971fbe735ca4.jpeg","width":2000,"height":2000},"variants":[{"id":"70f3b0fa-4faf-4d8c-8ef0-2413cc5dafc0","title":"","weight_unit":"oz","inventory_quantity":"151","sku":"99805","barcode":"191069998053","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"8.00","compare_at_price":"16.99","price":"16.99","available":true,"url":"\/products\/beets-gummies-beet-root-1200mg-antioxidant-cardiovascular-support?variant=70f3b0fa-4faf-4d8c-8ef0-2413cc5dafc0","available_quantity":"151","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/274fcaad6a38941f3801971fbe735ca4.jpeg","alt":"","path":"274fcaad6a38941f3801971fbe735ca4.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"4275791c-136f-4c40-a371-9ad9d0c707f1","title":"Beta Carotene 7500MCG RAE Rapid Release Softgels","brief":"","vendor":"CAPTEK SOFTGEL INTERNATIONAL","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"81","inventory_tracking":true,"published":true,"handle":"beta-carotene-7500mcg-rae-rapid-release-softgels","spu":"1223","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"29.99","price_max":"29.99","price":"29.99","compare_at_price":"29.99","compare_at_price_min":"29.99","compare_at_price_max":"29.99","url":"\/products\/beta-carotene-7500mcg-rae-rapid-release-softgels","sales":"69","image":{"src":"\/\/img.staticdj.com\/bffd563ed9a1ea9d29509fb4206cef31.jpeg","alt":"","path":"bffd563ed9a1ea9d29509fb4206cef31.jpeg","width":2000,"height":2000},"variants":[{"id":"c83464e3-5e40-42de-be9f-de36b4c08011","title":"","weight_unit":"lb","inventory_quantity":"81","sku":"1223","barcode":"191069712239","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"29.99","price":"29.99","available":true,"url":"\/products\/beta-carotene-7500mcg-rae-rapid-release-softgels?variant=c83464e3-5e40-42de-be9f-de36b4c08011","available_quantity":"81","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/bffd563ed9a1ea9d29509fb4206cef31.jpeg","alt":"","path":"bffd563ed9a1ea9d29509fb4206cef31.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/ac13688cf60e1e273237803f584bcacd.jpg","alt":"","path":"ac13688cf60e1e273237803f584bcacd.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"fe387e16-3321-4968-9e8f-6c9420bd4f6c","title":"Bi-Layered Melatonin 5 mg.","brief":"","vendor":"PROTAB LABORATORIES","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"244","inventory_tracking":true,"published":true,"handle":"bi-layered-melatonin-5-mg","spu":"53098","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"13.99","price_max":"13.99","price":"13.99","compare_at_price":"13.99","compare_at_price_min":"13.99","compare_at_price_max":"13.99","url":"\/products\/bi-layered-melatonin-5-mg","sales":"64","image":{"src":"\/\/img.staticdj.com\/9d3d40ac0fc4e55e47341b3e892016fc.jpg","alt":"","path":"9d3d40ac0fc4e55e47341b3e892016fc.jpg","width":2000,"height":2000},"variants":[{"id":"47730594-e46f-410b-9679-41267a93a45d","title":"","weight_unit":"lb","inventory_quantity":"244","sku":"53098","barcode":"191069530987","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"13.99","price":"13.99","available":true,"url":"\/products\/bi-layered-melatonin-5-mg?variant=47730594-e46f-410b-9679-41267a93a45d","available_quantity":"244","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/9d3d40ac0fc4e55e47341b3e892016fc.jpg","alt":"","path":"9d3d40ac0fc4e55e47341b3e892016fc.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/d896f01f84eb450acb65cc48fb1fcd3e.jpg","alt":"","path":"d896f01f84eb450acb65cc48fb1fcd3e.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/49b92e90d8ef361bfdddf174f7e3e4fc.jpg","alt":"","path":"49b92e90d8ef361bfdddf174f7e3e4fc.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"749c5bf5-b7eb-4503-a474-a69cfcb12858","title":"BioCell Collagen\u00ae Peptides with Resveratrol","brief":"","vendor":"ADH HEALTH PRODUCTS","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"429","inventory_tracking":true,"published":true,"handle":"biocell-collagen-peptides-with-resveratrol","spu":"99834","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"49.99","price_max":"49.99","price":"49.99","compare_at_price":"49.99","compare_at_price_min":"49.99","compare_at_price_max":"49.99","url":"\/products\/biocell-collagen-peptides-with-resveratrol","sales":"231","image":{"src":"\/\/img.staticdj.com\/1ffde303db60694dc05083fa7c893f78.jpeg","alt":"","path":"1ffde303db60694dc05083fa7c893f78.jpeg","width":2000,"height":2000},"variants":[{"id":"1271f460-f817-4d53-9115-f1afa1f80a2f","title":"","weight_unit":"lb","inventory_quantity":"429","sku":"99834","barcode":"191069998343","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"49.99","price":"49.99","available":true,"url":"\/products\/biocell-collagen-peptides-with-resveratrol?variant=1271f460-f817-4d53-9115-f1afa1f80a2f","available_quantity":"429","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/1ffde303db60694dc05083fa7c893f78.jpeg","alt":"","path":"1ffde303db60694dc05083fa7c893f78.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/0f6c5768181192ebe51d5894b47fdaa8.webp","alt":"","path":"0f6c5768181192ebe51d5894b47fdaa8.webp","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"968c5ed0-25eb-46c7-9d2a-702443de62f3","title":"Black Cherry 1000MG 100 Rapid Release Capsules","brief":"","vendor":"AMERICA'S BEST NUTRITION","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"black-cherry-1000mg-100-rapid-release-capsules","spu":"99751","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"18.99","price_max":"18.99","price":"18.99","compare_at_price":"18.99","compare_at_price_min":"18.99","compare_at_price_max":"18.99","url":"\/products\/black-cherry-1000mg-100-rapid-release-capsules","sales":"40","image":{"src":"\/\/img.staticdj.com\/d02e9a435b9fee71ccd96dca61ce0227.jpg","alt":"","path":"d02e9a435b9fee71ccd96dca61ce0227.jpg","width":2000,"height":2000},"variants":[{"id":"80abf427-9aec-43f5-a7ef-5556b9790d83","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"99751","barcode":"191069997513","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"18.99","price":"18.99","available":false,"url":"\/products\/black-cherry-1000mg-100-rapid-release-capsules?variant=80abf427-9aec-43f5-a7ef-5556b9790d83","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/d02e9a435b9fee71ccd96dca61ce0227.jpg","alt":"","path":"d02e9a435b9fee71ccd96dca61ce0227.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/2023275d47e6405254cd770252dff208.jpg","alt":"","path":"2023275d47e6405254cd770252dff208.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"1db5b6b0-9fdc-4f94-b283-ba0d94cfc276","title":"Calcium 600mg with Vitamin D3","brief":"","vendor":"ADH HEALTH PRODUCTS","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"0","inventory_tracking":true,"published":true,"handle":"calcium-600mg-with-vitamin-d3","spu":"99584","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":false,"price_min":"33.49","price_max":"33.49","price":"33.49","compare_at_price":"33.49","compare_at_price_min":"33.49","compare_at_price_max":"33.49","url":"\/products\/calcium-600mg-with-vitamin-d3","sales":"166","image":{"src":"\/\/img.staticdj.com\/eb7d426a2a2da3154405c91f14075407.jpeg","alt":"","path":"eb7d426a2a2da3154405c91f14075407.jpeg","width":2000,"height":2000},"variants":[{"id":"895c3e44-5b4a-49a6-bfe4-ede1ed9fa7fd","title":"","weight_unit":"lb","inventory_quantity":"0","sku":"99584","barcode":"191069995847","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"33.49","price":"33.49","available":false,"url":"\/products\/calcium-600mg-with-vitamin-d3?variant=895c3e44-5b4a-49a6-bfe4-ede1ed9fa7fd","available_quantity":"0","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/eb7d426a2a2da3154405c91f14075407.jpeg","alt":"","path":"eb7d426a2a2da3154405c91f14075407.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/3e4d16b5ffd298b5752c065cd7184492.jpg","alt":"","path":"3e4d16b5ffd298b5752c065cd7184492.jpg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"84f87a13-2796-462b-9bb6-5cfe967c3fcb","title":"Calcium Magnesium with Vitamin D3","brief":"","vendor":"AMERICA'S BEST NUTRITION","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"40","inventory_tracking":true,"published":true,"handle":"calcium-magnesium-with-vitamin-d3","spu":"61408","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"22.99","price_max":"22.99","price":"22.99","compare_at_price":"22.99","compare_at_price_min":"22.99","compare_at_price_max":"22.99","url":"\/products\/calcium-magnesium-with-vitamin-d3","sales":"473","image":{"src":"\/\/img.staticdj.com\/5ed1b0a5d78b03ea835b2adf723fe23f.jpg","alt":"","path":"5ed1b0a5d78b03ea835b2adf723fe23f.jpg","width":2000,"height":2000},"variants":[{"id":"eb508226-20e1-4c3c-bc73-bc4951272d73","title":"","weight_unit":"oz","inventory_quantity":"40","sku":"61408","barcode":"191069004655","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"11.70","compare_at_price":"22.99","price":"22.99","available":true,"url":"\/products\/calcium-magnesium-with-vitamin-d3?variant=eb508226-20e1-4c3c-bc73-bc4951272d73","available_quantity":"40","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/5ed1b0a5d78b03ea835b2adf723fe23f.jpg","alt":"","path":"5ed1b0a5d78b03ea835b2adf723fe23f.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/e054f60612a104cd1b19ae5701ce1b72.jpg","alt":"","path":"e054f60612a104cd1b19ae5701ce1b72.jpg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/fc3e25b1a64cf50908b78bced77d457f.jpg","alt":"","path":"fc3e25b1a64cf50908b78bced77d457f.jpg","width":1000,"height":1000}],"options":[],"product_type":"","discount_min_purchase_qty":0},{"id":"fe04522e-438d-4f3c-95a6-f8134649fa36","title":"Calcium Magnesium Zinc for Bones and Teeth","brief":"","vendor":"ROBINSON PHARMA","vendor_url":"","has_only_default_variant":true,"requires_shipping":true,"taxable":true,"inventory_policy":"deny","inventory_quantity":"214","inventory_tracking":true,"published":true,"handle":"calcium-magnesium-zinc-for-bones-and-teeth","spu":"4293","note":"","need_variant_image":false,"fake_sales":"0","display_fake_sales":false,"independent_seo":false,"available":true,"price_min":"26.99","price_max":"26.99","price":"26.99","compare_at_price":"26.99","compare_at_price_min":"26.99","compare_at_price_max":"26.99","url":"\/products\/calcium-magnesium-zinc-for-bones-and-teeth","sales":"880","image":{"src":"\/\/img.staticdj.com\/b93f478a885ba3e61e3cff78fcdb5312.webp","alt":"","path":"b93f478a885ba3e61e3cff78fcdb5312.webp","width":2000,"height":2000},"variants":[{"id":"bde39f91-6002-473e-8d30-7a52802d5a7e","title":"","weight_unit":"lb","inventory_quantity":"214","sku":"4293","barcode":"191069142937","position":1,"option1":"","option2":"","option3":"","note":"","image":null,"weight":"0.00","compare_at_price":"26.99","price":"26.99","available":true,"url":"\/products\/calcium-magnesium-zinc-for-bones-and-teeth?variant=bde39f91-6002-473e-8d30-7a52802d5a7e","available_quantity":"214","options":[],"is_hit_discount":true,"discount_info":{"total_price":"","total_received_discounts":"","discount_min_purchase_qty":0}}],"images":[{"src":"\/\/img.staticdj.com\/b93f478a885ba3e61e3cff78fcdb5312.webp","alt":"","path":"b93f478a885ba3e61e3cff78fcdb5312.webp","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/63e98d7198f17de21e5c537ec665fa4f.jpeg","alt":"","path":"63e98d7198f17de21e5c537ec665fa4f.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/f4d664ecf042fae7fe1ad5b23a22ac91.webp","alt":"","path":"f4d664ecf042fae7fe1ad5b23a22ac91.webp","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/8a0585be16b4055817032c0f9f8a7bdf.jpeg","alt":"","path":"8a0585be16b4055817032c0f9f8a7bdf.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/caed62d98cedfd2b67e30a7990d900f6.jpeg","alt":"","path":"caed62d98cedfd2b67e30a7990d900f6.jpeg","width":2000,"height":2000},{"src":"\/\/img.staticdj.com\/7b2821a76a99509580b4bf790dce129a.jpeg","alt":"","path":"7b2821a76a99509580b4bf790dce129a.jpeg","width":2000,"height":2000}],"options":[],"product_type":"","discount_min_purchase_qty":0}],"sort":{"by":"title","direction":"asc"},"has_removed":false,"has_insufficient_inventory":false,"count":156,"total_price":null},"obtain_product_info":{"page":1,"has_more":false,"product":[],"sort":null,"count":0},"discount_template_name":"default"} || {}; discountDefaultData.section_id = 15890337540001 || 1; this.discountDefaultData = discountDefaultData; this.discount_id = this.discountDefaultData.discount_info.id;// 活动id this.discountI18n = {}; const THEME_NAME = window.SHOPLAZZA.theme.merchant_theme_name || window.SHOP_PARAMS.theme_name; this.isHero = /Hero/.test(THEME_NAME); // PROGRESS_ONGOING: 进行中 PROGRESS_NOT_STARTED: 未开始 PROGRESS_FINISHED: 已结束 this.E_DISCOUNT_PROGRESS = { ProgressFinished : "PROGRESS_FINISHED", ProgressNotStarted : "PROGRESS_NOT_STARTED", ProgressOngoing : "PROGRESS_ONGOING" }; this.E_TAB_MAP = { scenario_buy : { value: "1", domId: "product_list_buy_products" }, scenario_obtain : { value: "2", domId: "product_list_obtain_products" } } this.tabContentIdMap = {}; this.currentTab = this.E_TAB_MAP.scenario_buy.value; this.model_buy = { discount_id: this.discount_id, //活动id scenario: 1, // 枚举值,1:购买商品,2:获得商品 sort: { by: 'recommend', direction: 'asc' }, page: 2, //分页码 limit: 20, // 每页数量 loading: false, // 请求数据标示 has_more: this.discountDefaultData.buy_product_info.has_more // 是否还有数据 }; this.model_get = { discount_id: this.discount_id, //活动id scenario: 2, // 枚举值,1:购买商品,2:获得商品 sort: { by: 'recommend', direction: 'asc' }, page: 2, limit: 20, loading: false, has_more: this.discountDefaultData.obtain_product_info?.has_more }; this.modelMap = { [this.E_TAB_MAP.scenario_buy.value]: this.model_buy, [this.E_TAB_MAP.scenario_obtain.value]: this.model_get, } this.sortDict = { recommend_asc: { by: 'recommend', direction: 'asc' }, title_asc: { by: 'title', direction: 'asc' }, title_desc: { by: 'title', direction: 'desc' }, price_asc: { by: 'price', direction: 'asc' }, price_desc: { by: 'price', direction: 'desc' }, created_at_desc: { by: 'created_at', direction: 'desc' }, sales_desc: { by: 'sales', direction: 'desc' }, add_to_cart_count_desc: { by: 'add_to_cart_count', direction: 'desc' }, views_desc: { by: 'views', direction: 'desc' } }; this.sortOptions = [ { value: 'recommend_asc', text: "Recommend" }, { value: 'price_asc', text: "Price, low to high" }, { value: 'price_desc', text: "Price, high to low" }, { value: 'title_asc', text: "Name, A to Z" }, { value: 'title_desc', text: "Name, Z to A" }, { value: 'created_at_desc', text: "Newest in" }, { value: 'sales_desc', text: "Total sales, high to low" }, { value: 'add_to_cart_count_desc', text: "Purchases, high to low" }, { value: 'views_desc', text: "Page views, high to low" } ]; // 直出商品数据 + 异步请求商品数据 this.products = this.discountDefaultData.buy_product_info.product; // 款式信息集合 this.productStyleInfo = []; // 弹窗内选择款式集合 this.modalVariantInfo = []; // 加购商品列表 this.lineItems = []; this.buyNowApi = "\/api\/checkout\/order"; this.batchAtcApi = "\/api\/cart\/batch"; this.debounceTimer = null; this.discount_type = this.discountDefaultData.discount_info.discount_type; this.discount_info = this.discountDefaultData.discount_info; } static deferredMount() { return false; } buildCallback() { this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); this.xhr_ = SPZServices.xhrFor(this.win); this.setupAction_(); Object.entries(this.E_TAB_MAP).forEach(([key, valueObj]) => { this.tabContentIdMap[valueObj.value] = valueObj.domId; }) this.getLocalLang(); console.log(this.discountDefaultData, 'discountDefaultData'); } async mountCallback() { this.utilsApi_ = await SPZ.whenApiDefined(document.querySelector('#spz_custom_utils')); this.init(); this.handleRenderSort(); } init() { this.xhr_.fetchJson(`/api/discount-i18n`, { method: "get", }).then((res)=>{ this.discountI18n = res; this.bindEvent(); }) // url 携带 sort_by参数 var queryParams = this.utilsApi_.params(); var sortValue = queryParams.sort_by; if (sortValue) { this.model_buy.sort = this.sortDict[sortValue]; } // 经典捆绑初始化商品数据 if(this.discount_type == 'DT_CLASSIC_BUNDLE') { this.productStyleInfo.push(...this.discountDefaultData.buy_product_info.product.map((item) => { return this.getFilteredVariants_(item, 'single'); })); } } // 获取本地的多语言 async getLocalLang() { const tempElement = document.getElementById('spz-custom-lang-script'); SPZ.whenApiDefined(tempElement).then(async (api) => { this.currentLangMap = await api.getLang(); }); } handleRenderSort() { // 渲染排序 const sort_x_id = 'promotionSortProductsX'; const $sortX = document.getElementById(sort_x_id) $sortX && SPZ.whenApiDefined($sortX).then((api) => { // 渲染排序列表 api.doRender_({options: this.sortOptions, defaultValue: 'recommend_asc', id: sort_x_id }); }) const sort_y_id = 'promotionSortProductsY'; const $sortY = document.getElementById(sort_y_id) $sortY && SPZ.whenApiDefined($sortY).then((api) => { // 渲染排序列表 api.doRender_({options: this.sortOptions, defaultValue: 'recommend_asc' , id: sort_y_id}); }) } // 获取数据,拼接html模板 async getData() { // 请求数据 let model = this.modelMap[this.currentTab]; if (!model.has_more || model.loading) { return; } model.loading = true; this.handleLoading_({type: 'product', action: 'show'}); let $content = document.querySelector(`#${this.tabContentIdMap[this.currentTab]} .discount-default__productlist-wrap`) || document.querySelector(`.discount-default__productlist-wrap`); let $defaultEmpty = $content && $content.querySelector('.discount_default_empty'); //查询活动商品接口 const reqBody = { discount_id: model.discount_id, page: model.page, limit: model.limit, apply_scenario: model.scenario, sort: model.sort, sales_channel: { sale_channel_type: "online", sale_channel_id: '1199785' } } this.xhr_.fetchJson(`/api/storefront/promotion/landing_page/product/list`, { method: "post", body: reqBody }).then(async(res)=>{ // 更新参与活动的商品数量 const productCount = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionEventProductCount`); productCount && SPZ.whenApiDefined(productCount).then((api) => { api.render(res.count, true); }); this.products.push(...res.products); this.handleLoading_({type: 'product', action: 'close'}); const count = res.count; model.has_more = res.has_more; if (count > 0) { $defaultEmpty && ($defaultEmpty.style.display = 'none'); model.page++; if (res.products && res.products.length > 0) { let products = res.products.map((product) => { return { ...product, url: this.utilsApi_.globalizePath(product.url), image_padding_bottom: this.utilsApi_.image_padding_bottom(product.image.width, product.image.height,'no-limit') } }); // 获取商品列表渲染模板, dom挂载 const renderApi = await SPZ.whenApiDefined(document.querySelector('#discounts_products_render')); const el = await renderApi.getRenderTemplate({ products: products, discountI18n: this.discountI18n, discount_info: this.discountDefaultData.discount_info, }); const childNodes = el.querySelectorAll('.as-render-product-item'); if (childNodes && childNodes.length > 0) { $content.append(...el.childNodes); } if(this.discount_type == 'DT_CLASSIC_BUNDLE') { // 遍历$content 插入商品垂直虚线分割 const productListAsync = $content.querySelectorAll('.as-render-product-item'); if (productListAsync.length > 0) { productListAsync.forEach((item, index) => { const htmlStr = `<span class="promotion_dotted_line"></span> <div class="promotion_plus_bundle"> <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none"> <path d="M1 6H11M6 1L6 11" stroke="black" stroke-width="1.6" stroke-linecap="round"/> </svg> </div> <span class="promotion_dotted_line"></span>`; this.createAndInsertSeparator_('promotion_separator md:hidden', (index + 1) % 4 !== 0 && index !== productListAsync.length - 1, htmlStr, $content, item); this.createAndInsertSeparator_('promotion_separator lg:hidden', (index + 1) % 2 !== 0 && index !== productListAsync.length - 1, htmlStr, $content, item); }); } } if(this.discount_type == 'DT_MIX_MATCH_BUNDLE') { const productSelector = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionProductSelector`); productSelector && SPZ.whenApiDefined(productSelector).then((api) => { api.init(); }); const currentPageSelectedProducts = res.products.filter(item => this.productStyleInfo.map(item => item.product_id).includes(item.id)); this.updateProductPrice_(currentPageSelectedProducts); } } } else { // 空列表 const $emptyTemplate = document.querySelector('#promotionDiscountEmpty .discount_default_empty'); const $cloneEmptyTemplate = $emptyTemplate.cloneNode(true); $content.innerHTML = ''; $content.append($cloneEmptyTemplate); $defaultEmpty && ($defaultEmpty.style.display = 'flex'); } model.loading = false; }).catch((err)=>{ this.handleRequestError_(err); }).finally(()=>{ model.loading = false; this.handleLoading_({type: 'product', action: 'close'}); // 经典spu纬度需要该商品信息: is_classic_bundle_product_list_variant_tag if(this.discount_type == 'DT_CLASSIC_BUNDLE' && this.discount_info.enable_min_purchase_qty == true && this.discount_info.min_purchase_qty_type == 'spu') { this.productStyleInfo = this.productStyleInfo.map((item) => { return { ...item, is_classic_bundle_product_list_variant_tag: true, } }); } const result = this.productStyleInfo.reduce((map, item) => { if (!map[item.product_id]) { map[item.product_id] = []; } map[item.product_id].push(item); return map; }, {}); // 渲染变体tags if(this.discount_type == 'DT_MIX_MATCH_BUNDLE' || this.discount_type == 'DT_CLASSIC_BUNDLE') { Object.values(result).forEach((item) => { this.handleSpzVariantRender_(item, item[0].product_id); this.handleProductOption_(item[0].product_id, true); }); } // 渲染经典额外变体 if(this.discount_type == 'DT_CLASSIC_BUNDLE' && this.discount_info.enable_min_purchase_qty == true && this.discount_info.min_purchase_qty_type == 'spu') { Object.values(result).forEach((item) => { if(item[0].is_multi_style && item[0].discount_min_purchase_qty > 1) { const classicSpuTag = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionClassicSpuTags-${item[0].product_id}`); classicSpuTag && SPZ.whenApiDefined(classicSpuTag).then((api) => { api.render(item, true); }); } }); } // 渲染经典捆绑商品最低购买数量 if(this.discount_type == 'DT_CLASSIC_BUNDLE') { Object.values(result).forEach((item) => { this.handleMinPurchaseQtyUpdate_({discount_min_purchase_qty: item[0].discount_min_purchase_qty}, item[0].product_id); }); } }) } createAndInsertSeparator_(className, condition, htmlStr, $content, item) { if (condition) { const separator = document.createElement('div'); separator.className = className; separator.innerHTML = htmlStr; $content.insertBefore(separator, item.nextSibling); } } bindEvent() { // 监听滚动,请求数据 window.addEventListener("scroll", this.utilsApi_.debounce( () => { // 判断是否到底 const model = this.modelMap[this.currentTab]; if (!model.loading && model.has_more && this.utilsApi_.isToPageEnd(this.discountDefaultData.section_id)) { this.getData(); } }, 10, 50 )) } // 商品排序 handleSort_(data) { let sortKey = data.value; this.modelMap[this.currentTab].sort = this.sortDict[sortKey || 'recommend_asc']; this.modelMap[this.currentTab].page = 1; this.modelMap[this.currentTab].has_more = true; this.productStyleInfo = this.handleMixMatchBundleFilterSelected_(this.productStyleInfo); // 清空商品列表dom, 重新请求排序数据渲染 let $productList = document.querySelector(`#${this.tabContentIdMap[this.currentTab]} .discount-default__productlist-wrap`) || document.querySelector(`.discount-default__productlist-wrap`);; $productList && ($productList.innerHTML = ''); this.getData(); } // tab 切换 tabChange_(value) { this.currentTab = value || this.E_TAB_MAP.scenario_buy.value; } // 渲染界面 doRender_(data) { return this.templates_ .findAndRenderTemplate(this.element, data) .then((el) => { const children = this.element.querySelector('*:not(template)'); children && SPZCore.Dom.removeElement(children); this.element.appendChild(el); }); } // 捆绑商品加购/立即购买 handleBundleAddToCart_(data) { const { action } = data; if(this.discount_type == 'DT_CLASSIC_BUNDLE') { this.lineItems = this.productStyleInfo; } else { this.lineItems = this.handleMixMatchBundleFilterSelected_(this.productStyleInfo); } if(action == 'cart') { //add to cart this.xhr_ .fetchJson(this.batchAtcApi, { method: 'POST', body: { line_items: this.lineItems.map((item) => { return { product_id: item.product_id, variant_id: item.variant_id, quantity: item.quantity } }) } }) .then(data => { setTimeout(() => { window.location.href = '/cart'; }); }) .catch(async (error) => { await error.then((data) => { this.handleRequestError_(data); }); }); } else { //checkout this.xhr_ .fetchJson(this.buyNowApi, { method: 'POST', body: { line_items: (this.lineItems || []).map((product) => { return { quantity: product.quantity, variant_id: product.variant_id, note: product.note || '', properties: product.properties || {} } }), refer_info: { source: 'buy_now' } } }) .then(async (data) => { if (data.state === 'success') { window.location.href = data.data?.checkout_url; } else { this.handleRequestError_(data); } }) .catch(async (error) => { await error.then((data) => { this.handleRequestError_(data); }); }); } } handleRequestError_(data) { const message = data?.message || data?.errors?.[0] || 'Unknown error'; const toast = SPZCore.Dom.scopedQuerySelector(document.body, '#discount_toast'); toast && SPZ.whenApiDefined(toast).then((api) => { api.showToast(message); }); }; // 渲染加购弹窗内容 async renderQuickShop(data) { this.handleLoading_({type: 'whole', action: 'show'}); const apply_scenario = this.modelMap[this.currentTab].scenario; this.xhr_.fetchJson(`/api/storefront/promotion/landing_page/product?product_id=${data.product_id}&discount_id=${this.discount_id}&apply_scenario=${apply_scenario}`, { method: "get", }).then(async(res)=>{ this.handleLoading_({type: 'whole', action: 'close'}); const $quickShop = await SPZ.whenApiDefined(document.querySelector('#promotion-quick-view-render')); // 定义默认渲染的子款式 const selectedVariant = res.product.variants.find((v)=> (v.available && v.is_hit_discount == true)) || res.product.variants[0]; let selectedValues = {}; selectedVariant.options.length && selectedVariant.options.forEach(item => { selectedValues[item.name] = item.value; }) // 默认选中的 子款式、 options res.product.defaultSelectValues = selectedValues; let data = {...res.product, product:res.product, selectedVariant}; $quickShop.render(data); // 打开加购弹窗 SPZ.whenApiDefined(document.querySelector(`#promotion-quick-view`)).then((api)=>{ api.open(); }); }).catch((err)=>{ this.handleLoading_({type: 'whole', action: 'close'}); }) } // 单变体点击添加按钮 renderSingleVariant(data) { const { product_id } = data; const currentProduct = this.products.find((product) => product.id == product_id); // 若当前商品已存在,则不再添加 而是更新数量 const index = this.productStyleInfo.findIndex((item) => item.product_id == product_id); if (index != -1) { this.productStyleInfo[index].quantity = Number(this.productStyleInfo[index].quantity) + 1; this.updateProductPrice_(this.productStyleInfo); } else { this.productStyleInfo.push(this.getFilteredVariants_(currentProduct, 'single')); } const renderProductArr = this.productStyleInfo.filter((item) => item.product_id == product_id); this.handleSpzVariantRender_(renderProductArr, product_id); this.handleProductOption_(product_id, true); } // 过滤选中商品的子款式 获取有用的信息 product_id,variant_id,price,compare_at_price,quantity,title,variant_title getFilteredVariants_(data, type = '') { const { id, title, variants, inventory_tracking, inventory_policy, inventory_quantity, product_type, discount_min_purchase_qty } = data; const { product_id, variant_id, variant, quantity, product } = data; const isSingle = type == 'single'; const variantData = isSingle ? (variants[0] || data) : variant; const productData = isSingle ? data : product; let item_quantity = 0; if (this.discount_type === 'DT_MIX_MATCH_BUNDLE') { item_quantity = isSingle ? 1 : Number(quantity); } else if (type === 'classic_spu') { item_quantity = 1; } else { item_quantity = discount_min_purchase_qty || productData.discount_min_purchase_qty || variantData.discount_info.discount_min_purchase_qty || 1; } return { product_id: isSingle ? id : product_id, variant_id: variantData?.id || '', price: variantData?.price || '0.00', compare_at_price: variantData?.compare_at_price || '0.00', quantity: item_quantity, inventory_tracking: productData.inventory_tracking, inventory_policy: productData.inventory_policy, inventory_quantity: productData.inventory_quantity, product_type: productData.product_type || this.products.find((item) => item.id == product_id)?.product_type || this.products.find((item) => item.id == id)?.product_type || '', title: productData.title, variant_title: variantData?.options.map((option) => option.value).join('/') || '', is_multi_style: productData.variants.length > 1, discount_min_purchase_qty: discount_min_purchase_qty || productData.discount_min_purchase_qty || variantData.discount_info.discount_min_purchase_qty || 0, } } // 更新价格方法 updateProductPrice_(data) { const bottomBtnContainer = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionBottomContainer`); if (data.length == 0) { bottomBtnContainer && SPZ.whenApiDefined(bottomBtnContainer).then((api) => { api.render({original_price: 0, received_discounts: 0}, true); }); return; } data = this.handleMixMatchBundleFilterSelected_(data); const reqBody = { discount_id: this.discount_id, customer: { customer_id: '', email: '', }, sales_channel: { sale_channel_type: "online", sale_channel_id: '1199785' }, line_items: data } // 如果已经有一个请求在等待,那么取消这个请求 if (this.debounceTimer) { clearTimeout(this.debounceTimer); } this.handleLoading_({type: 'whole', action: 'show'}); this.debounceTimer = setTimeout(() => { this.xhr_.fetchJson(`/api/storefront/promotion/calculate/discounted_price`, { method: "post", body: reqBody }).then((res)=>{ // 更新商品列表价格 Object.keys(res.line_items).forEach((key) => { const currentProductPrice = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionProductPrice-${key}`); currentProductPrice && SPZ.whenApiDefined(currentProductPrice).then((api) => { api.render(res.line_items[key], true); }); }); // 更新底部按钮总价/总折扣价 const picked_qty = data.reduce((acc, item) => { return acc + item.quantity; }, 0); bottomBtnContainer && SPZ.whenApiDefined(bottomBtnContainer).then((api) => { api.render({...res.total_price, picked_qty}, true); }); }).catch(async (err)=>{ await err.then((data) => { this.handleRequestError_(data); }); }).finally(()=>{ this.handleLoading_({type: 'whole', action: 'close'}); }) }, 100); } // 还原商品价格 resetProductPrice_(data) { const {price, compare_at_price, id} = data; const currentProductPrice = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionProductPrice-${id}`); currentProductPrice && SPZ.whenApiDefined(currentProductPrice).then((api) => { api.render({total_received_discounts: price, total_price: compare_at_price}, true); }); } // 处理与selector组件的交互 handleProductOption_(productId, show) { const currentProductOption = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionSelectOption-${productId}`); if(!currentProductOption) return; currentProductOption.toggleAttribute('show', show); const productSelector = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionProductSelector`); productSelector && SPZ.whenApiDefined(productSelector).then((api) => { api.toggle_({option: productId, value: show}); }); } // 调用spz-tag组件的doRender方法 handleSpzVariantRender_(data, id) { const spzVariantTag = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionSpzVariantTags-${id}`); spzVariantTag && SPZ.whenApiDefined(spzVariantTag).then((api) => { api.render(data, true); }); } // 执行经典捆绑最低购买数量更新 handleMinPurchaseQtyUpdate_(data, id) { const minPruchaseQty = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionMinPurchaseQty-${id}`); minPruchaseQty && SPZ.whenApiDefined(minPruchaseQty).then((api) => { api.render(data, true); }); } // 添加商品子款式 renderVariantTag() { let variantInfo; const quickShopBody = SPZCore.Dom.scopedQuerySelector(document.body, '#promotion-quick-shop-body'); quickShopBody && SPZ.whenApiDefined(quickShopBody).then((api) => { variantInfo = api.getVariantsData(); console.log(variantInfo, 'variantInfo'); const productId = variantInfo.product_id; const variantId = variantInfo.variant_id; const minPruchaseQtyRender = variantInfo.product.discount_min_purchase_qty || variantInfo.variant.discount_info.discount_min_purchase_qty; if(this.discount_type == 'DT_MIX_MATCH_BUNDLE') { const index = this.productStyleInfo.findIndex((item) => item.variant_id == variantInfo.variant_id); if (index != -1) { this.productStyleInfo[index].quantity = Number(this.productStyleInfo[index].quantity) + Number(variantInfo.quantity); this.updateProductPrice_(this.productStyleInfo); } else { this.productStyleInfo.push(this.getFilteredVariants_(variantInfo)); // 若当前商品已选中,更新商品价格 const currentProductOption = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionSelectOption-${productId}`); const isSelected = currentProductOption && currentProductOption.hasAttribute('selected'); isSelected && this.updateProductPrice_(this.productStyleInfo); } const selectedVariantsFilter = this.productStyleInfo.filter((item) => item.product_id == productId); this.handleSpzVariantRender_(selectedVariantsFilter, productId); this.handleProductOption_(productId, true); } else { if(this.discount_info.enable_min_purchase_qty == true && this.discount_info.min_purchase_qty_type == 'spu' && minPruchaseQtyRender > 1) { const index = this.modalVariantInfo.findIndex((item) => item.variant_id == variantId); if (index != -1) { this.modalVariantInfo[index].quantity = Number(this.modalVariantInfo[index].quantity) + 1; } else { this.modalVariantInfo.push(this.getFilteredVariants_(variantInfo, 'classic_spu')); } const modalVariantTag = SPZCore.Dom.scopedQuerySelector(document.body, '#promotionModalVariantTagRender'); modalVariantTag && SPZ.whenApiDefined(modalVariantTag).then((api) => { api.render(this.modalVariantInfo, true); }); this.handleModalInventoryCheck_(variantInfo); const selectedVariantsNum = this.modalVariantInfo.reduce((acc, item) => { return acc + item.quantity; }, 0); if(selectedVariantsNum == minPruchaseQtyRender) { this.handleSpzVariantRender_([this.getFilteredVariants_(variantInfo)], productId); this.productStyleInfo = this.productStyleInfo.filter((item) => item.product_id != productId).concat(this.modalVariantInfo); const renderData = this.productStyleInfo.filter((item) => item.product_id == productId).map((item) => { return { ...item, is_classic_bundle_product_list_variant_tag: true } }); const classicSpuTag = SPZCore.Dom.scopedQuerySelector(document.body, `#promotionClassicSpuTags-${productId}`); classicSpuTag && SPZ.whenApiDefined(classicSpuTag).then((api) => { api.render(renderData, true); }); this.updateProductPrice_(this.productStyleInfo); const quickView = SPZCore.Dom.scopedQuerySelector(document.body, '#promotion-quick-view'); quickView && SPZ.whenApiDefined(quickView).then((api)=>{ api.close(); }); this.modalVariantInfo = []; } else { return; } } // this.productStyleInfo 中已存在与productId, variantId都相同的商品 则直接return 关闭弹窗 const isExist = this.productStyleInfo.some((item) => item.product_id == productId && item.variant_id == variantId); if (isExist) { const quickView = SPZCore.Dom.scopedQuerySelector(document.body, '#promotion-quick-view'); quickView && SPZ.whenApiDefined(quickView).then((api)=>{ api.close(); }); return; } // 更新this.productStyleInfo中的商品款式信息 const index = this.productStyleInfo.findIndex((item) => item.product_id == productId); if (index != -1) { this.productStyleInfo[index] = this.getFilteredVariants_(variantInfo); } const selectedVariantsFilter = this.productStyleInfo.filter((item) => item.product_id == productId); this.handleSpzVariantRender_(selectedVariantsFilter, productId); this.handleMinPurchaseQtyUpdate_({discount_min_purchase_qty: minPruchaseQtyRender}, productId); this.updateProductPrice_(this.productStyleInfo); } const quickView = SPZCore.Dom.scopedQuerySelector(document.body, '#promotion-quick-view'); quickView && SPZ.whenApiDefined(quickView).then((api)=>{ api.close(); }); }); } // 混搭弹窗内的前端库存校验 handleModalInventoryCheck_(data) { if(this.discount_type == 'DT_CLASSIC_BUNDLE') { const currentVariantAddNum = this.modalVariantInfo.find((item) => item.variant_id == data.variant_id)?.quantity || 0; const quickShopBody = SPZCore.Dom.scopedQuerySelector(document.body, '#promotion-quick-shop-body'); if(!!data.variant && currentVariantAddNum == Number(data.variant.available_quantity)) { quickShopBody && quickShopBody.setAttribute('status', 'soldout'); } else { quickShopBody && quickShopBody.setAttribute('status', 'available'); } } } // 删除商品子款式 deleteVariantTag(data) { const { product_id, variant_id } = data; if(this.discount_info.enable_min_purchase_qty == true && this.discount_info.min_purchase_qty_type == 'spu') { const modalProductVariants = this.modalVariantInfo.filter((item) => item.product_id == product_id && item.variant_id != variant_id); const modalVariantTag = SPZCore.Dom.scopedQuerySelector(document.body, '#promotionModalVariantTagRender'); modalVariantTag && SPZ.whenApiDefined(modalVariantTag).then((api) => { api.render(modalProductVariants, true); }); this.handleModalInventoryCheck_(data); this.modalVariantInfo = modalProductVariants; return; } const currentProductVariants = this.productStyleInfo.filter((item) => item.product_id == product_id && item.variant_id != variant_id); this.handleSpzVariantRender_(currentProductVariants, product_id); // 更新selectedVariants this.productStyleInfo = this.productStyleInfo.filter((item) => item.variant_id != variant_id); if(currentProductVariants.length > 0) { // currentProductVariants 中只要有一项是多款式商品,就更新价格 const isMultiStyle = currentProductVariants.some((item) => item.is_multi_style); isMultiStyle && this.updateProductPrice_(this.productStyleInfo); this.handleProductOption_(product_id, true); } else { this.handleProductOption_(product_id, false); this.resetProductPrice_(this.products.find((item) => item.id == product_id)); } } // 加购弹窗未参与活动 加购按钮不可点击 handleNotHitDiscount_(data) { const $quickShopBody = document.querySelector('#promotion-quick-shop-body'); //当前子框式未命中活动 if(data.variant.is_hit_discount == false) { $quickShopBody.setAttribute('variantstatus', 'notHitDiscount') } else { $quickShopBody.setAttribute('variantstatus', '') } } // loading handleLoading_(event) { const { type, action } = event; const loadingElementId = type == 'product' ? '#promotionProductsLoading' : '#promotionWholeLoading'; const loadingElement = document.querySelector(loadingElementId); if (loadingElement) { SPZ.whenApiDefined(loadingElement).then((api) => { if (action == 'show') { api.show_(); } else { api.close_(); } }); } } handleSelectProduct(productArr) { // 从this.productStyleInfo 过滤出选中的商品 const selectedProducts = this.productStyleInfo.filter((item) => productArr.includes(item.product_id)); this.updateProductPrice_(selectedProducts); } handleMixMatchBundleFilterSelected_(data) { const selectedOptions = SPZCore.Dom.scopedQuerySelectorAll(document.body, '[id^="promotionSelectOption-"]'); const idArr = [...selectedOptions].reduce((acc, item) => { if (item.hasAttribute('selected')) { const optionValue = item.getAttribute('option'); if (optionValue) { acc.push(optionValue); } } return acc; }, []); if(this.discount_type == 'DT_MIX_MATCH_BUNDLE') { return data.filter((item) => idArr.includes(item.product_id)); } return data; } setupAction_() { this.registerAction('handleTabChange', (invocation) => { const { panelId } = invocation.args.data; this.tabChange_(panelId); }); // 监听排序组件 选中选项 this.registerAction('handleSort', (invocation) => { const data = invocation.args.data; this.handleSort_(data); }); // 渲染加购弹窗 this.registerAction('renderQuickShop', (invocation) => { const data = invocation.args; this.renderQuickShop(data); }); this.registerAction('renderSingleVariant', (invocation) => { const data = invocation.args; this.renderSingleVariant(data); }); // 捆绑商品加购/立即购买 this.registerAction('handleBundleAddToCart', (invocation) => { const data = invocation.args; this.handleBundleAddToCart_(data); }); // 子款式 未参与活动 this.registerAction('handleNotHitDiscount', (invocation) => { const data = invocation.args.data; this.handleNotHitDiscount_(data); }); // 加购提示 this.registerAction('handleAddToCartToast', (invocation) => { const langValue = this.currentLangMap['add_to_cart_successfully']; this.triggerEvent_("addToCartToast", langValue); }); this.registerAction('getVariantInfo', (invocation) => { this.renderVariantTag(); }); this.registerAction('deleteVariantTag', (invocation) => { const data = invocation.args; this.deleteVariantTag(data); }); this.registerAction('getSelectedProduct', (invocation) => { const data = invocation.args.data; this.handleSelectProduct(data); }); this.registerAction('pageReload', () => { window.location.reload(); }); this.registerAction('resetModalVariantInfo', () => { this.modalVariantInfo = []; }); this.registerAction('handleModalInventoryCheck', (invocation) => { const data = invocation.args.data; this.handleModalInventoryCheck_(data); }); this.registerAction('changeTextSoldOut', (invocation) => { const data = invocation.args.data; const addBtn = SPZCore.Dom.scopedQuerySelector(document.body, '.promotion-shop-btn[role="confirm"]'); if(!addBtn) return; const content = SPZCore.Dom.scopedQuerySelector(addBtn, '[role="content"]'); if (content) { const langValue = this.currentLangMap[data.variant.available ? 'add' : 'sold_out']; content.innerHTML = langValue; } }); } triggerEvent_(name, data) { const event = SPZUtils.Event.create(this.win, `${ TAG }.${ name }`, data || {}); this.action_.trigger(this.element, name, event); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } } SPZ.defineElement(TAG, SpzCustomDiscountDefault)
156
Sort by