UNPKG

@eastsideco/escshopify

Version:

WIP JS library for Shopify, containing a variety of useful functionality.

283 lines (256 loc) 16.6 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../../"> <title data-ice="title">src/entities/Shop.js | @eastsideco/escshopify</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="./manual/index.html" data-ice="manualHeaderLink">Manual</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> <a href="https://bitbucket.org/sigapps/escshopify.git">Repository</a></header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-entities">entities</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-plugins">plugins</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-utils">utils</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-external">E</span><span data-ice="name"><span><a href="https://www.npmjs.com/package/evee">evee</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-external">E</span><span data-ice="name"><span><a href="https://www.npmjs.com/package/js-money">js-money</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-external">E</span><span data-ice="name"><span><a href="https://www.npmjs.com/package/promise-queue">promise-queue</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#entities">entities</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/entities/Cart.js~Cart.html">Cart</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/entities/Shop.js~Shop.html">Shop</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/entities/index.js~Entities.html">Entities</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyCart">ShopifyCart</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyCartLineItem">ShopifyCartLineItem</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyAddress">ShopifyAddress</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyPolicy">ShopifyPolicy</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyShop">ShopifyShop</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#http">http</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/http/RequestQueuable.js~RequestQueuable.html">RequestQueuable</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins">plugins</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/index.js~Plugins.html">Plugins</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins-easycurrency">plugins/easycurrency</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/EasyCurrency.js~EasyCurrency.html">EasyCurrency</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/MoneySpan.js~MoneySpan.html">MoneySpan</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/MoneySpanSet.js~MoneySpanSet.html">MoneySpanSet</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/Session.js~Session.html">Session</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/config.js~Config.html">Config</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/state.js~State.html">State</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins-easycurrency-formatters">plugins/easycurrency/formatters</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/formatters/DefaultFormatter.js~DefaultFormatter.html">DefaultFormatter</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/formatters/Formatter.js~Formatter.html">Formatter</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins-easycurrency-helpers">plugins/easycurrency/helpers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/helpers/SelectHelper.js~SelectHelper.html">SelectHelper</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins-easycurrency-resolvers">plugins/easycurrency/resolvers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/resolvers/CurrencyResolver.js~CurrencyResolver.html">CurrencyResolver</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/easycurrency/resolvers/GeoserviceResolver.js~GeoserviceResolver.html">GeoserviceResolver</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#plugins-geoservice">plugins/geoservice</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/geoservice/API.js~API.html">API</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/plugins/geoservice/GeoService.js~GeoService.html">GeoService</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSContinent">GSContinent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCountry">GSCountry</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCurrencyRates">GSCurrencyRates</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCurrencyResponse">GSCurrencyResponse</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSGeoResponse">GSGeoResponse</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSLocation">GSLocation</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSTranslatedString">GSTranslatedString</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/Log.js~Log.html">Log</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/general.js~GeneralUtils.html">GeneralUtils</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils-loggers">utils/loggers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/ConsoleLogger.js~ConsoleLogger.html">ConsoleLogger</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/Logger.js~Logger.html">Logger</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/logLevel.js~LogLevel.html">LogLevel</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-logLevel">logLevel</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/entities/Shop.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import Evee from &apos;evee&apos;; import Queue from &apos;promise-queue&apos;; import deepEqual from &apos;deep-equal&apos;; import _ from &apos;lodash&apos;; import config from &apos;config&apos;; import log from &apos;log&apos;; const TAG = &apos;Shop&apos;; /** * @typedef {Object} ShopifyShop * @property {ShopifyAddress} address * @property {Number} collections_count * @property {String} currency * @property {String} description * @property {String} domain * @property {String} email * @property {String[]} enabled_payment_types * @property {String} locale * @property {String} money_format * @property {String} money_format_with_currency * @property {String} name * @property {String} password_message * @property {String} permanent_domain * @property {ShopifyPolicy[]} policies * @property {String} refund_policy * @property {String} secure_url * @property {String} terms_of_service * @property {String[]} types * @property {String} url * @property {String[]} vendors */ /** * @typedef {Object} ShopifyAddress * @property {String} address1 * @property {String} address2 * @property {String} city * @property {String|null} company * @property {String} country * @property {String} country_code * @property {String|null} first_name * @property {String|null} last_name * @property {Number|null} latitude * @property {Number|null} longitude * @property {String|null} name * @property {String|null} phone * @property {String|null} province * @property {String|null} province_code * @property {String|null} zip */ /** * @typedef {Object} ShopifyPolicy * @property {String} body * @property {String} title */ /** * Shopify Shop entity. * @extends {evee} */ export default class Shop extends Evee { /** * Construct a new instance of the shop entity. */ constructor() { super(); /** @type {ShopifyAddress} */ this.address = null; /** @type {Number} */ this.collections_count = null; /** @type {String} */ this.currency = null; /** @type {String} */ this.description = null; /** @type {String} */ this.domain = null; /** @type {String} */ this.email = null; /** @type {String[]} */ this.enabled_payment_types = []; /** @type {String} */ this.locale = null; /** @type {String} */ this.money_format = null; /** @type {String} */ this.money_format_with_currency = null; /** @type {String} */ this.name = null; /** @type {String} */ this.password_message = null; /** @type {String} */ this.permanent_domain = null; /** @type {ShopifyPolicy[]} */ this.policies = []; /** @type {String} */ this.refund_policy = null; /** @type {String} */ this.secure_url = null; /** @type {String} */ this.terms_of_service = null; /** @type {String[]} */ this.types = []; /** @type {String} */ this.url = null; /** @type {String[]} */ this.vendors = []; } /** * Initialize the shop entity with the global shop state. * @param {ShopifyShop} shopData - Shopify shop object. */ initialize(shopData) { this._loadFromShopifyShop(shopData); this.emit(&apos;init&apos;, { shop: this }); log.send(log.DEBUG, TAG, &apos;Loaded.&apos;); } /** * Loads properties from the given shop. * @param {ShopifyShop} shop */ _loadFromShopifyShop(shop) { this.address = shop.address; this.collections_count = shop.collections_count; this.currency = shop.currency; this.description = shop.description; this.domain = shop.domain; this.email = shop.email; this.enabled_payment_types = shop.enabled_payment_types; this.locale = shop.locale; this.money_format = shop.money_format; this.money_format_with_currency = shop.money_format_with_currency; this.name = shop.name; this.password_message = shop.password_message; this.permanent_domain = shop.permanent_domain; this.policies = shop.policies; this.refund_policy = shop.refund_polcy; this.secure_url = shop.secure_url; this.terms_of_service = shop.terms_of_service; this.types = shop.types; this.url = shop.url; this.vendors = shop.vendors; } /** * Normalizes a relative URL according to the current pathname. * @param {String} rel * @returns {String} */ _normalizeRelativeUrl(rel) { var normal = relative; if (normal.length &gt; 0 &amp;&amp; normal[0] != &apos;/&apos;) { normal = window.location.pathname + normal; } } /** * Generates an absolute URL containing the shop primary domain. * @param {String} relative - A relative URL to make absolute (i.e. &apos;/collections/all&apos;) * @returns {String} */ makeAbsoluteUrl(relative) { var normal = this._normalizeRelativeUrl(relative); return this.secure_url + normal; } /** * Generates an absolute URL containing the shop&apos;s myshopify domain. * @param {String} relative - A relative URL to make absolute (i.e. &apos;/collections/all&apos;) * @returns {String} */ makePermanentUrl(relative) { var normal = this._normalizeRelativeUrl(relative); return this.secure_url.replace(this.domain, this.permanent_domain) + normal; } } </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>