{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./assets/src/js/easyshade-add-to-cart.js","webpack:///./assets/src/js/utils/cart-utils.js","webpack:///./assets/src/js/utils/ga-ecommerce-utils.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","EasyShadeAddToCart","this","getModelAndHousingCodesUrl","window","itemPrefix","addToCartBtn","document","querySelector","qtyIpts","querySelectorAll","orderItems","orderFormattedAsLineItems","modelHousingCodes","addToCartRedirectUrl","addToOrderLine","addToCartErrorMessage","init","Promise","resolve","reject","fetch","method","headers","accept","then","response","ok","json","catch","console","error","length","classList","remove","removeAttribute","location","addToEpiCart","gaAddToCart","shift","addToCart","displayAddToCartError","model","housingColor","code","find","Name","Id","lineItem","sizeVal","modelVal","shadeColorVal","housingColorVal","modelHousingCode","getModelCodeForOrder","leftMotorMount","alert","log","map","ipt","ct","parseInt","closest","lineItemCode","getLineItemOrderCode","push","itemNumber","quantity","that","getGetModelAndHousingCodeData","data","addEventListener","add","setAttribute","createOrderQueue","body","JSON","stringify","lineItems","noItemsSelectedErrorMessage","getEpiCartItems","url","protocol","hostname","removeFromEpiCart","pushToDataLayer","dataLayer","ecommerce","getEventData","checkout","event","addPaymentInfo","paymentType","addShippingInfo","type","href","target","indexOf","viewCart","viewItem","viewItemList","category"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS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AASE,OAAOH,KAAKL,MAGxBS,MAAMC,QAAQC,WA0Bf0D,EAAW,WAEfD,EAAaA,yBACV/D,MAAK,mBACJ4D,EAAgB,CACdK,MAAO,iBACPH,kB,EAiFNI,eA7GqB,SAACC,GAEtBJ,EAAaA,2CAD0CI,GAEpDnE,MAAK,mBACJ4D,EAAgB,CACdK,MAAO,mBACPH,kB,EAwGNM,gBAnGsB,WAEtBL,EAAaA,gCACV/D,MAAK,mBACJ4D,EAAgB,CACdK,MAAO,oBACPH,kB,EA8FNE,W,EACAnD,YA/EkB,SAACM,EAAMkD,GAEzB,OAAO,IAAI5E,SAAQ,SAACC,EAASC,GAC3BC,MAAMA,+BAFmCuB,EAEzC,SAFsDkD,EAE3C,CACTxE,OAAQ,OACRC,QAAS,CACPC,OAAQ,mBACR,eAAgB,sBAGjBC,MAAK,SAACC,GACDA,EAASC,GACXD,EAASE,OACNH,MAAK,SAAC8D,GACLF,EAAgB,CACdK,MAAO,cACPH,iBAGH9D,KAAKN,GAERO,EAASE,OAAOH,KAAKL,MAGxBS,MAAMC,QAAQC,W,EAwDnBd,KApDW,WAEXV,SAASgE,iBAAiB,SAAS,SAACmB,GAAW,IAErCK,EADWL,EAAXM,OACAD,KACJA,IACgC,IAA9B,EAAKE,QAAQ,aACfR,Q,EA8CNJ,kB,EACAa,SAzCe,WAEfV,EAAaA,yBACV/D,MAAK,mBACJ4D,EAAgB,CACdK,MAAO,YACPH,kB,EAoCNY,SA/Be,SAACvD,EAAMkD,GAEtBN,EAAaA,8BAD6B5C,EAC1C,SADuDkD,GAEpDrE,MAAK,mBACJ4D,EAAgB,CACdK,MAAO,YACPH,kB,EA0BNa,aArBmB,SAACC,GAEpBb,EAAaA,kCADiCa,GAE3C5E,MAAK,SAAC8D,GACa,OAAd,GACJF,EAAgB,CACdK,MAAO,iBACPH","file":"easyshade-add-to-cart.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/* eslint-disable no-console */\nimport { addToEpiCart } from './utils/cart-utils';\nimport { gaAddToCart } from './utils/ga-ecommerce-utils';\n\nexport default class EasyShadeAddToCart {\n constructor() {\n this.getModelAndHousingCodesUrl = window.getModelAndHousingCodesUrl;\n this.itemPrefix = window.itemPrefix;\n this.addToCartBtn = document.querySelector('.add-to-cart-btn');\n this.qtyIpts = document.querySelectorAll('.line-item-quantity');\n this.orderItems = [];\n this.orderFormattedAsLineItems = [];\n this.modelHousingCodes = [];\n this.addToCartRedirectUrl = window.addToCartRedirectUrl;\n this.addToOrderLine = window.addToCartRedirectUrl;\n this.addToCartErrorMessage = window.addToCartErrorMessage;\n this.init();\n }\n\n getGetModelAndHousingCodeData() {\n return new Promise((resolve, reject) => {\n fetch(this.getModelAndHousingCodesUrl, {\n method: 'GET',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n },\n })\n .then((response) => {\n if (response.ok) {\n response.json().then(resolve);\n } else {\n response.json().then(reject);\n }\n })\n .catch(console.error);\n });\n }\n\n addToCart() {\n // console.log(this.orderItems);\n if (this.orderItems.length === 0) {\n this.addToCartBtn.classList.remove('updating');\n this.addToCartBtn.removeAttribute('disabled');\n window.location = this.addToCartRedirectUrl;\n return;\n }\n addToEpiCart(this.orderItems[0])\n .then(() => {\n gaAddToCart(this.orderItems[0], 'EasyShades')\n .then(() => {\n // Remove item added from array\n this.orderItems.shift();\n // Rerun addToCart until empty\n this.addToCart();\n })\n .catch((error) => {\n this.displayAddToCartError(error);\n });\n })\n .catch((error) => {\n this.displayAddToCartError(error);\n });\n }\n\n getModelCodeForOrder(model, housingColor) {\n const code = this.modelHousingCodes.find(c => c.Name === `${model}${housingColor}`);\n if (code) {\n return code.Id;\n }\n return '';\n }\n\n getLineItemOrderCode(lineItem) {\n const sizeVal = lineItem.querySelector('.line-item-size').value;\n const modelVal = lineItem.querySelector('.line-item-model').value;\n const shadeColorVal = lineItem.querySelector('.line-item-shade-color').value;\n const housingColorVal = lineItem.querySelector('.line-item-housing-color').value;\n const modelHousingCode = this.getModelCodeForOrder(modelVal, housingColorVal);\n const leftMotorMount = (modelVal === '2') ? 'L' : '';\n if (modelHousingCode === '') {\n return '';\n }\n return `${this.itemPrefix}${modelHousingCode}${shadeColorVal}${sizeVal}${leftMotorMount}`;\n }\n\n displayAddToCartError(error) {\n const { alert } = window;\n console.log(error);\n alert(this.addToCartErrorMessage);\n this.addToCartBtn.classList.remove('updating');\n this.addToCartBtn.removeAttribute('disabled');\n }\n\n createOrderQueue() {\n // Wipe any items from previous order queue\n this.orderItems = [];\n this.orderFormattedAsLineItems = [];\n // Loop through line items w/ a quantity specified\n [].map.call(this.qtyIpts, (ipt) => {\n if (ipt.value !== '' && ipt.value !== '0') {\n const ct = parseInt(ipt.value, 10);\n const lineItem = ipt.closest('tr');\n const lineItemCode = this.getLineItemOrderCode(lineItem);\n // Add to cart/order queue\n for (let i = 0; i < ct; i++) { /* eslint-disable-line no-plusplus */\n this.orderItems.push(lineItemCode);\n }\n // Add object to this.orderFormattedAsLineItems\n this.orderFormattedAsLineItems.push({\n itemNumber: lineItemCode,\n quantity: ct,\n });\n }\n });\n }\n\n init() {\n const that = this;\n // Get model codes needed to create item number on order\n this.getGetModelAndHousingCodeData()\n .then((data) => {\n this.modelHousingCodes = data;\n });\n\n if (this.addToCartBtn) {\n this.addToCartBtn.addEventListener('click', () => {\n this.addToCartBtn.classList.add('updating');\n this.addToCartBtn.setAttribute('disabled', 'disabled');\n that.createOrderQueue();\n // If queue is empty, throw alert\n if (this.orderItems.length === 0) {\n this.addToCartBtn.classList.remove('updating');\n this.addToCartBtn.removeAttribute('disabled');\n const { alert, noItemsSelectedErrorMessage } = window;\n alert(noItemsSelectedErrorMessage);\n return;\n }\n // Add to order lines before adding to EPi cart\n fetch('AddToCart', {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n lineItems: this.orderFormattedAsLineItems,\n }),\n })\n .then(that.addToCart())\n .catch((error) => {\n this.displayAddToCartError(error);\n });\n });\n }\n }\n}\nwindow.EasyShadeAddToCart = EasyShadeAddToCart;\n/* eslint-enable no-console */\n","const getEpiCartItems = () => { // getCartItems()\n const url = `${window.location.protocol}//${window.location.hostname}/api/v1/cart`;\n return new Promise((resolve, reject) => {\n fetch(url)\n .then(r => r.json())\n .then(resolve)\n .catch(reject);\n });\n};\n\nconst addToEpiCart = code => ( // addToCart()\n new Promise((resolve, reject) => {\n fetch(`${window.location.protocol}//${window.location.hostname}/api/v1/cart/items/${code}`, {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n },\n })\n .then((r) => {\n if (r.ok) {\n r.json().then(resolve);\n } else {\n r.json().then(reject);\n }\n })\n .catch(reject);\n })\n);\n\n\nconst removeFromEpiCart = (code) => { // removeFromCart()\n const url = `${window.location.protocol}//${window.location.hostname}/api/v1/cart/items/${code}`;\n return new Promise((resolve, reject) => {\n fetch(url, { method: 'DELETE' })\n .then((r) => {\n if (r.ok) {\n resolve();\n } else {\n r.json().then(reject);\n }\n })\n .catch(reject);\n });\n};\n\nexport {\n getEpiCartItems,\n addToEpiCart,\n removeFromEpiCart,\n};\n","/* eslint-disable no-console */\nconst pushToDataLayer = (data) => {\n console.log(data);\n const { dataLayer } = window;\n if (dataLayer === null || data === null) return;\n dataLayer.push({ ecommerce: null });\n dataLayer.push(data);\n};\n\nconst getEventData = url => (\n new Promise((resolve, reject) => {\n fetch(url, {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n },\n })\n .then((response) => {\n if (response.ok) {\n response.json().then(resolve);\n } else {\n response.json().then(reject);\n }\n })\n .catch(console.error);\n })\n);\n\nconst addPaymentInfo = (paymentType) => {\n const url = `/ga/AddPaymentInfoFormatter?paymentType=${paymentType}`;\n getEventData(url)\n .then(ecommerce => (\n pushToDataLayer({\n event: 'add_payment_info',\n ecommerce,\n })\n ));\n};\n\nconst addShippingInfo = () => {\n const url = '/ga/AddShippingInfoFormatter';\n getEventData(url)\n .then(ecommerce => (\n pushToDataLayer({\n event: 'add_shipping_info',\n ecommerce,\n })\n ));\n};\n\nconst checkout = () => {\n const url = '/ga/CheckoutFormatter';\n getEventData(url)\n .then(ecommerce => (\n pushToDataLayer({\n event: 'begin_checkout',\n ecommerce,\n })\n ));\n};\n\nconst gaAddToCart = (code, type) => {\n const url = `/ga/AddToCartFormatter?code=${code}&type=${type}`;\n return new Promise((resolve, reject) => {\n fetch(url, {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n },\n })\n .then((response) => {\n if (response.ok) {\n response.json()\n .then((ecommerce) => {\n pushToDataLayer({\n event: 'add_to_cart',\n ecommerce,\n });\n })\n .then(resolve);\n } else {\n response.json().then(reject);\n }\n })\n .catch(console.error);\n });\n};\n\nconst init = () => {\n // Add in catch for all checkout buttons\n document.addEventListener('click', (event) => {\n const { target } = event;\n const { href } = target;\n if (href) {\n if (href.indexOf('checkout') !== -1) {\n checkout();\n }\n }\n });\n};\n\nconst viewCart = () => {\n const url = '/ga/ViewCartFormatter';\n getEventData(url)\n .then(ecommerce => (\n pushToDataLayer({\n event: 'view_cart',\n ecommerce,\n })\n ));\n};\n\nconst viewItem = (code, type) => {\n const url = `/ga/ViewItemFormatter?code=${code}&type=${type}`;\n getEventData(url)\n .then(ecommerce => (\n pushToDataLayer({\n event: 'view_item',\n ecommerce,\n })\n ));\n};\n\nconst viewItemList = (category) => {\n const url = `/ga/ViewItemListFormatter?name=${category}`;\n getEventData(url)\n .then((ecommerce) => {\n if (ecommerce === null) return;\n pushToDataLayer({\n event: 'view_item_list',\n ecommerce,\n });\n });\n};\n\nexport {\n addPaymentInfo,\n addShippingInfo,\n checkout,\n gaAddToCart,\n init,\n pushToDataLayer,\n viewCart,\n viewItem,\n viewItemList,\n};\n/* eslint-enable no-console */\n"],"sourceRoot":""}