@eastsideco/escshopify
Version:
WIP JS library for Shopify, containing a variety of useful functionality.
1,642 lines • 263 kB
JSON
[
{
"__docId__": 1,
"kind": "external",
"name": "Infinity",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Infinity",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 2,
"kind": "external",
"name": "NaN",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~NaN",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 3,
"kind": "external",
"name": "undefined",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~undefined",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 4,
"kind": "external",
"name": "null",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~null",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 5,
"kind": "external",
"name": "Object",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Object",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 6,
"kind": "external",
"name": "object",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~object",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 7,
"kind": "external",
"name": "Function",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Function",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 8,
"kind": "external",
"name": "function",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~function",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 9,
"kind": "external",
"name": "Boolean",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Boolean",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 10,
"kind": "external",
"name": "boolean",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~boolean",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 11,
"kind": "external",
"name": "Symbol",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Symbol",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 12,
"kind": "external",
"name": "Error",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Error",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 13,
"kind": "external",
"name": "EvalError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~EvalError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 14,
"kind": "external",
"name": "InternalError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~InternalError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 15,
"kind": "external",
"name": "RangeError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~RangeError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 16,
"kind": "external",
"name": "ReferenceError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~ReferenceError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 17,
"kind": "external",
"name": "SyntaxError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~SyntaxError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 18,
"kind": "external",
"name": "TypeError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~TypeError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 19,
"kind": "external",
"name": "URIError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~URIError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 20,
"kind": "external",
"name": "Number",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Number",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 21,
"kind": "external",
"name": "number",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~number",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 22,
"kind": "external",
"name": "Date",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Date",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 23,
"kind": "external",
"name": "String",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~String",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 24,
"kind": "external",
"name": "string",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~string",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 25,
"kind": "external",
"name": "RegExp",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~RegExp",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 26,
"kind": "external",
"name": "Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 27,
"kind": "external",
"name": "Int8Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int8Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 28,
"kind": "external",
"name": "Uint8Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint8Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 29,
"kind": "external",
"name": "Uint8ClampedArray",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint8ClampedArray",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 30,
"kind": "external",
"name": "Int16Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int16Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 31,
"kind": "external",
"name": "Uint16Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint16Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 32,
"kind": "external",
"name": "Int32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 33,
"kind": "external",
"name": "Uint32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 34,
"kind": "external",
"name": "Float32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Float32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 35,
"kind": "external",
"name": "Float64Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Float64Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 36,
"kind": "external",
"name": "Map",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Map",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 37,
"kind": "external",
"name": "Set",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Set",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 38,
"kind": "external",
"name": "WeakMap",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~WeakMap",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 39,
"kind": "external",
"name": "WeakSet",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~WeakSet",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 40,
"kind": "external",
"name": "ArrayBuffer",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~ArrayBuffer",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 41,
"kind": "external",
"name": "DataView",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~DataView",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 42,
"kind": "external",
"name": "JSON",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~JSON",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 43,
"kind": "external",
"name": "Promise",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Promise",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 44,
"kind": "external",
"name": "Generator",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Generator",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 45,
"kind": "external",
"name": "GeneratorFunction",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~GeneratorFunction",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 46,
"kind": "external",
"name": "Reflect",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Reflect",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 47,
"kind": "external",
"name": "Proxy",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Proxy",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 48,
"kind": "file",
"name": "src/config.js",
"content": "/** @ignore */\nexport default {\n debug: process.env.NODE_ENV != 'production',\n logPrefix: 'escshopify',\n};\n",
"static": true,
"longname": "/home/kiran-price/Projects/_esc_shopify_js/v2/src/config.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 49,
"kind": "file",
"name": "src/entities/Cart.js",
"content": "import Evee from 'evee';\nimport Queue from 'promise-queue';\nimport deepEqual from 'deep-equal';\nimport _ from 'lodash';\n\nimport config from 'config';\nimport log from 'log';\nimport ajaxApi from 'http/shopifyAJAXAPI';\n\nconst TAG = 'Cart';\n\n\n/**\n * @typedef {Object} ShopifyCartLineItem\n * @property {Number} id\n * @property {Object|null} properties\n * @property {Number} quantity\n * @property {Number} variant_id\n * @property {String} key\n * @property {String} title\n * @property {Number} price\n * @property {Number} original_price\n * @property {Number} discounted_price\n * @property {Number} original_line_price\n * @property {Number} line_price\n * @property {Number} total_discount\n * @property {Object[]} discounts\n * @property {String|null} sku\n * @property {Number} grams\n * @property {String} vendor\n * @property {Boolean} taxable\n * @property {Number} product_id\n * @property {Boolean} gift_card\n * @property {String} url\n * @property {String|null} image\n * @property {String} handle\n * @property {Boolean} requires_shipping\n * @property {String|null} product_type\n * @property {String} product_title\n * @property {String|null} product_description\n * @property {String} variant_title\n * @property {String[]} variant_options\n */\n\n/**\n * @typedef {Object} ShopifyCart\n * @property {String} token\n * @property {String} note\n * @property {Object} attributes\n * @property {Number} total_price\n * @property {Number} total_weight\n * @property {ShopifyCartLineItem[]} items\n * @property {Boolean} requires_shipping\n */\n\n/**\n * Shopify Cart entity.\n * @extends {evee}\n */\nexport default class Cart extends Evee {\n /**\n * Construct a new instance of the cart entity.\n */\n constructor() {\n super();\n\n /** @type {promise-queue} */\n this._queue = new Queue(1, Infinity);\n this._attributes = {};\n this._ready = false;\n\n /** @type {Object[]} */\n this._items = [];\n this._attributes = {};\n }\n\n /**\n * Initialize the cart entity with the current state of the visitor's cart.\n * @param {ShopifyCart} cartData - Shopify Cart object.\n */\n initialize(cartData) {\n this._loadFromShopifyCart(cartData);\n\n this._emitUpdate('init', null);\n if (this.items.length == 0) {\n this._emitClear([]);\n }\n\n log.send(log.DEBUG, TAG, 'Loaded.');\n }\n\n /**\n * Alias to getItems();\n * @type {ShopifyCartLineItem[]}\n */\n get items() { return this.getItems(); }\n /**\n * Returns items in the cart (in the normal Shopify line item format.\n * @returns {ShopifyCartLineItem[]}\n */\n getItems() {\n return this._items;\n }\n\n /**\n * Alias to getTotalPrice();\n * @type {Number}\n */\n get total_price() { return this.getTotalPrice(); }\n /**\n * Alias to getTotalPrice();\n * @type {Number}\n */\n get totalPrice() { return this.getTotalPrice(); }\n /**\n * Calculates the total value of the cart.\n * @returns {Number}\n */\n getTotalPrice() {\n return _.reduce(this.items, (total, item) => {\n return total + item.line_price;\n }, 0)\n }\n\n /**\n * Reloads the cart state via AJAX.\n * @returns {Promise<src/entities/Cart.js~Cart, Error>}\n */\n async reload() {\n var cartData = await ajaxApi.get('/cart.js');\n this._loadFromShopifyCart(cartData.data);\n return this;\n }\n \n\n\n\n /**\n * Alias to getAttributes()\n * @type {Object}\n */\n get attributes() { return this.getAttributes(); }\n /**\n * Returns cart attributes.\n * @returns {Object}\n */\n getAttributes() {\n return this._attributes;\n }\n\n /**\n * Sets all attributes on the cart. This will override/remove existing attributes.\n * @param {Object} attributes - New attributes for the cart.\n * @returns {Promise<src/entities/Cart.js~Cart, Error>}\n */\n setAttributes(attributes) {\n log.sendObject(log.DEBUG, TAG, 'Setting attributes...', {\n attributes\n });\n return this._queue.add(async () => {\n var cart = await ajaxApi.post({attributes});\n this._loadFromShopifyCart(cart.data);\n this._emitUpdate('attribute-updated', null);\n });\n }\n\n getAttribute(key) {\n return this._attributes[key];\n }\n\n setAttribute(key, value) {\n log.sendObject(log.DEBUG, TAG, 'Setting attribute...', {\n key,\n value\n });\n return this._queue.add(async () => {\n var newAttributes = Object.assign({}, this._attributes);\n newAttributes[key] = value;\n var cart = await ajaxApi.post({attributes: newAttributes});\n this._loadFromShopifyCart(cart.data);\n this._emitUpdate('attribute-updated', null);\n });\n }\n\n\n /**\n * Add a new item to the cart.\n * @param {Number|String} id - Variant ID to add to cart.\n * @param {Number} quantity - Quantity to add.\n * @param {Object} properties - Line item attributes.\n * @returns {Promise<ShopifyCartLineItem, Error>}\n */\n addItem(id, quantity, properties) {\n log.sendObject(log.DEBUG, TAG, 'Queuing addItem...', {\n id,\n quantity,\n properties\n });\n return this._queue.add(async () => {\n var res = await ajaxApi.post('/cart/add.js', {\n id,\n quantity,\n properties\n });\n var data = res.data;\n log.sendObject(log.DEBUG, TAG, 'addItem resonse', data);\n if (data.id) {\n var item = this._loadItem(data);\n this._emitAdd(item);\n this._emitUpdate('add', item);\n return item;\n }\n throw new Error(data);\n });\n }\n\n updateItem(lineNumber, quantity, properties) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n removeItem(lineNumber) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n updateItemById(id, quantity, properties) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n updateItemById(id, quantity, properties) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n updateItemQuantitiesById(updates) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n removeItemById(id) {\n return this._queue.add(() => {\n return new Promise((acc, rej) => {\n\n });\n });\n }\n\n /**\n * Clear the cart.\n * @returns {Promise<src/entities/Cart.js~Cart, Error>}\n */\n clear() {\n return this._queue.add(async () => {\n var cartData = await ajaxApi.post('/cart/clear.js');\n var oldItems = this.items;\n this._loadFromShopifyCart(cartData);\n this._emitClear(oldItems);\n });\n }\n\n\n _loadItem(itemData) {\n for (var item of this.items) {\n if (item.id == itemData.id && deepEqual(item.properties, itemData.properties)) {\n item.quantity = itemData.quantity;\n return item;\n }\n }\n\n this.items.push(itemData);\n return itemData;\n }\n\n _emitUpdate(operation, item) {\n var data ={\n items: this.items,\n operation,\n item\n };\n log.sendObject(log.DEBUG, TAG, 'Event: update', data);\n this.emit('update', data);\n }\n\n _emitClear(oldItems) {\n var data ={\n oldItems\n };\n log.sendObject(log.DEBUG, TAG, 'Event: clear', data);\n this.emit('clear', data);\n }\n\n _emitAdd(item) {\n var data ={\n items: this.items,\n item\n };\n log.sendObject(log.DEBUG, TAG, 'Event: add', data);\n this.emit('add', data);\n }\n\n _emitUpdateItem(item) {\n var data ={\n items: this.items,\n item\n };\n log.sendObject(log.DEBUG, TAG, 'Event: updae-item', data);\n this.emit('update-item', data);\n }\n\n _emitRemove(item) {\n var data = {\n items: this.items,\n item\n };\n log.sendObject(log.DEBUG, TAG, 'Event: remove', data);\n this.emit('clear', data);\n }\n\n _loadFromShopifyCart(cart) {\n this._items = cart.items || [];\n }\n}\n",
"static": true,
"longname": "/home/kiran-price/Projects/_esc_shopify_js/v2/src/entities/Cart.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 50,
"kind": "variable",
"name": "TAG",
"memberof": "src/entities/Cart.js",
"static": true,
"longname": "src/entities/Cart.js~TAG",
"access": "public",
"export": false,
"importPath": "@eastsideco/escshopify/src/entities/Cart.js",
"importStyle": null,
"description": null,
"lineNumber": 10,
"undocument": true,
"type": {
"types": [
"string"
]
},
"ignore": true
},
{
"__docId__": 51,
"kind": "typedef",
"name": "ShopifyCartLineItem",
"memberof": "src/entities/Cart.js",
"static": true,
"longname": "src/entities/Cart.js~ShopifyCartLineItem",
"access": "public",
"description": "",
"properties": [
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "id",
"description": ""
},
{
"nullable": null,
"types": [
"Object",
"null"
],
"spread": false,
"optional": false,
"name": "properties",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "quantity",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "variant_id",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "key",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "title",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "original_price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "discounted_price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "original_line_price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "line_price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "total_discount",
"description": ""
},
{
"nullable": null,
"types": [
"Object[]"
],
"spread": false,
"optional": false,
"name": "discounts",
"description": ""
},
{
"nullable": null,
"types": [
"String",
"null"
],
"spread": false,
"optional": false,
"name": "sku",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "grams",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "vendor",
"description": ""
},
{
"nullable": null,
"types": [
"Boolean"
],
"spread": false,
"optional": false,
"name": "taxable",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "product_id",
"description": ""
},
{
"nullable": null,
"types": [
"Boolean"
],
"spread": false,
"optional": false,
"name": "gift_card",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "url",
"description": ""
},
{
"nullable": null,
"types": [
"String",
"null"
],
"spread": false,
"optional": false,
"name": "image",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "handle",
"description": ""
},
{
"nullable": null,
"types": [
"Boolean"
],
"spread": false,
"optional": false,
"name": "requires_shipping",
"description": ""
},
{
"nullable": null,
"types": [
"String",
"null"
],
"spread": false,
"optional": false,
"name": "product_type",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "product_title",
"description": ""
},
{
"nullable": null,
"types": [
"String",
"null"
],
"spread": false,
"optional": false,
"name": "product_description",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "variant_title",
"description": ""
},
{
"nullable": null,
"types": [
"String[]"
],
"spread": false,
"optional": false,
"name": "variant_options",
"description": ""
}
],
"type": {
"types": [
"Object"
],
"optional": false,
"name": "ShopifyCartLineItem"
}
},
{
"__docId__": 52,
"kind": "typedef",
"name": "ShopifyCart",
"memberof": "src/entities/Cart.js",
"static": true,
"longname": "src/entities/Cart.js~ShopifyCart",
"access": "public",
"description": "",
"properties": [
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "token",
"description": ""
},
{
"nullable": null,
"types": [
"String"
],
"spread": false,
"optional": false,
"name": "note",
"description": ""
},
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "attributes",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "total_price",
"description": ""
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "total_weight",
"description": ""
},
{
"nullable": null,
"types": [
"ShopifyCartLineItem[]"
],
"spread": false,
"optional": false,
"name": "items",
"description": ""
},
{
"nullable": null,
"types": [
"Boolean"
],
"spread": false,
"optional": false,
"name": "requires_shipping",
"description": ""
}
],
"type": {
"types": [
"Object"
],
"optional": false,
"name": "ShopifyCart"
}
},
{
"__docId__": 53,
"kind": "class",
"name": "Cart",
"memberof": "src/entities/Cart.js",
"static": true,
"longname": "src/entities/Cart.js~Cart",
"access": "public",
"export": true,
"importPath": "@eastsideco/escshopify/src/entities/Cart.js",
"importStyle": "Cart",
"description": "Shopify Cart entity.",
"lineNumber": 60,
"interface": false,
"extends": [
"evee"
]
},
{
"__docId__": 54,
"kind": "constructor",
"name": "constructor",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#constructor",
"access": "public",
"description": "Construct a new instance of the cart entity.",
"lineNumber": 64
},
{
"__docId__": 55,
"kind": "member",
"name": "_queue",
"memberof": "src/entities/Cart.js~Cart",
"static": false,
"longname": "src/entities/Cart.js~Cart#_queue",
"access": "private",
"description": null,
"lineNumber": 68,
"type": {
"nullable": null,
"types": [
"promise-queue"
],
"spread": false,
"description": null
}
},
{
"__docId__": 56,
"kind": "member",
"name": "_attributes",
"memberof": "src/entities/Cart.js~Cart",
"static": false,
"longname": "src/entities/Cart.js~Cart#_attributes",
"access": "private",
"description": null,
"lineNumber": 69,
"undocument": true,
"type": {
"types": [
"{}"
]
}
},
{
"__docId__": 57,
"kind": "member",
"name": "_ready",
"memberof": "src/entities/Cart.js~Cart",
"static": false,
"longname": "src/entities/Cart.js~Cart#_ready",
"access": "private",
"description": null,
"lineNumber": 70,
"undocument": true,
"type": {
"types": [
"boolean"
]
}
},
{
"__docId__": 58,
"kind": "member",
"name": "_items",
"memberof": "src/entities/Cart.js~Cart",
"static": false,
"longname": "src/entities/Cart.js~Cart#_items",
"access": "private",
"description": null,
"lineNumber": 73,
"type": {
"nullable": null,
"types": [
"Object[]"
],
"spread": false,
"description": null
}
},
{
"__docId__": 60,
"kind": "method",
"name": "initialize",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#initialize",
"access": "public",
"description": "Initialize the cart entity with the current state of the visitor's cart.",
"lineNumber": 81,
"params": [
{
"nullable": null,
"types": [
"ShopifyCart"
],
"spread": false,
"optional": false,
"name": "cartData",
"description": "Shopify Cart object."
}
],
"return": null
},
{
"__docId__": 61,
"kind": "get",
"name": "items",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#items",
"access": "public",
"description": "Alias to getItems();",
"lineNumber": 96,
"type": {
"nullable": null,
"types": [
"ShopifyCartLineItem[]"
],
"spread": false,
"description": null
}
},
{
"__docId__": 62,
"kind": "method",
"name": "getItems",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#getItems",
"access": "public",
"description": "Returns items in the cart (in the normal Shopify line item format.",
"lineNumber": 101,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{ShopifyCartLineItem[]}"
}
],
"return": {
"nullable": null,
"types": [
"ShopifyCartLineItem[]"
],
"spread": false,
"description": ""
},
"params": []
},
{
"__docId__": 63,
"kind": "get",
"name": "total_price",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#total_price",
"access": "public",
"description": "Alias to getTotalPrice();",
"lineNumber": 109,
"type": {
"nullable": null,
"types": [
"Number"
],
"spread": false,
"description": null
}
},
{
"__docId__": 64,
"kind": "get",
"name": "totalPrice",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#totalPrice",
"access": "public",
"description": "Alias to getTotalPrice();",
"lineNumber": 114,
"type": {
"nullable": null,
"types": [
"Number"
],
"spread": false,
"description": null
}
},
{
"__docId__": 65,
"kind": "method",
"name": "getTotalPrice",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#getTotalPrice",
"access": "public",
"description": "Calculates the total value of the cart.",
"lineNumber": 119,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Number}"
}
],
"return": {
"nullable": null,
"types": [
"Number"
],
"spread": false,
"description": ""
},
"params": []
},
{
"__docId__": 66,
"kind": "method",
"name": "reload",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": true,
"static": false,
"longname": "src/entities/Cart.js~Cart#reload",
"access": "public",
"description": "Reloads the cart state via AJAX.",
"lineNumber": 129,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Promise<src/entities/Cart.js~Cart, Error>}"
}
],
"return": {
"nullable": null,
"types": [
"Promise<src/entities/Cart.js~Cart, Error>"
],
"spread": false,
"description": ""
},
"params": []
},
{
"__docId__": 67,
"kind": "get",
"name": "attributes",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#attributes",
"access": "public",
"description": "Alias to getAttributes()",
"lineNumber": 142,
"type": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 68,
"kind": "method",
"name": "getAttributes",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#getAttributes",
"access": "public",
"description": "Returns cart attributes.",
"lineNumber": 147,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Object}"
}
],
"return": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": ""
},
"params": []
},
{
"__docId__": 69,
"kind": "method",
"name": "setAttributes",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#setAttributes",
"access": "public",
"description": "Sets all attributes on the cart. This will override/remove existing attributes.",
"lineNumber": 156,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Promise<src/entities/Cart.js~Cart, Error>}"
}
],
"params": [
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "attributes",
"description": "New attributes for the cart."
}
],
"return": {
"nullable": null,
"types": [
"Promise<src/entities/Cart.js~Cart, Error>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 70,
"kind": "method",
"name": "getAttribute",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#getAttribute",
"access": "public",
"description": null,
"lineNumber": 167,
"undocument": true,
"params": [
{
"name": "key",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 71,
"kind": "method",
"name": "setAttribute",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#setAttribute",
"access": "public",
"description": null,
"lineNumber": 171,
"undocument": true,
"params": [
{
"name": "key",
"types": [
"*"
]
},
{
"name": "value",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 72,
"kind": "method",
"name": "addItem",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#addItem",
"access": "public",
"description": "Add a new item to the cart.",
"lineNumber": 193,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Promise<ShopifyCartLineItem, Error>}"
}
],
"params": [
{
"nullable": null,
"types": [
"Number",
"String"
],
"spread": false,
"optional": false,
"name": "id",
"description": "Variant ID to add to cart."
},
{
"nullable": null,
"types": [
"Number"
],
"spread": false,
"optional": false,
"name": "quantity",
"description": "Quantity to add."
},
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "properties",
"description": "Line item attributes."
}
],
"return": {
"nullable": null,
"types": [
"Promise<ShopifyCartLineItem, Error>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 73,
"kind": "method",
"name": "updateItem",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#updateItem",
"access": "public",
"description": null,
"lineNumber": 217,
"undocument": true,
"params": [
{
"name": "lineNumber",
"types": [
"*"
]
},
{
"name": "quantity",
"types": [
"*"
]
},
{
"name": "properties",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 74,
"kind": "method",
"name": "removeItem",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#removeItem",
"access": "public",
"description": null,
"lineNumber": 225,
"undocument": true,
"params": [
{
"name": "lineNumber",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 75,
"kind": "method",
"name": "updateItemById",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#updateItemById",
"access": "public",
"description": null,
"lineNumber": 233,
"undocument": true,
"params": [
{
"name": "id",
"types": [
"*"
]
},
{
"name": "quantity",
"types": [
"*"
]
},
{
"name": "properties",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 76,
"kind": "method",
"name": "updateItemById",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#updateItemById",
"access": "public",
"description": null,
"lineNumber": 241,
"undocument": true,
"params": [
{
"name": "id",
"types": [
"*"
]
},
{
"name": "quantity",
"types": [
"*"
]
},
{
"name": "properties",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 77,
"kind": "method",
"name": "updateItemQuantitiesById",
"memberof": "src/entities/Cart.js~Cart",
"generator": false,
"async": false,
"static": false,
"longname": "src/entities/Cart.js~Cart#updateItemQuantitiesById",
"access": "public",
"description": null,
"lineNumber": 249,
"undocument": true