@dotdev/locations
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -146,7 +146,34 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
StoreLocations.prototype.setHomeStore = function SetACookieOfTheUsersLocation(data) { | ||
StoreLocations.prototype.setHomeStore = function SetACookieAndMetafieldOfTheUsersLocation(config) { | ||
'use strict'; | ||
const string = JSON.stringify(data); | ||
Cookie.set('HomeStore', string, { expires: 365 }); | ||
const options = config || {}; | ||
const { locationId, customerId } = options; | ||
const data = { | ||
location_id: locationId, | ||
customer_id: customerId | ||
}; | ||
options.success = options.success || function setHomeStore(response) { | ||
const success = JSON.parse(response); | ||
const successEvent = new CustomEvent('homestore:set', { | ||
detail: { | ||
response: success | ||
} | ||
}); | ||
document.dispatchEvent(successEvent); | ||
}; | ||
options.error = options.error || this.defaultError; | ||
Cookie.set('HomeStore', data, { expires: 365 }); | ||
const request = { | ||
url: this.settings.url + '/customers/default-location' + this.settings.params, | ||
success: options.success, | ||
method: 'PUT', | ||
error: options.error, | ||
data: data | ||
}; | ||
this.queue.add(request); | ||
return this; | ||
@@ -185,3 +212,3 @@ }; | ||
const request = { | ||
url: this.settings.url + ('/orders/' + id + '/return') + this.settings.params, | ||
url: this.settings.url + '/orders/' + id + '/return' + this.settings.params, | ||
success: options.success, | ||
@@ -188,0 +215,0 @@ method: 'POST', |
@@ -140,6 +140,33 @@ import Q from '@dotdev/ajax-queue' | ||
StoreLocations.prototype.setHomeStore = function SetACookieOfTheUsersLocation (data) { | ||
StoreLocations.prototype.setHomeStore = function SetACookieAndMetafieldOfTheUsersLocation (config) { | ||
'use strict' | ||
const string = JSON.stringify(data) | ||
Cookie.set('HomeStore', string, { expires: 365 }) | ||
const options = config || {} | ||
const { locationId, customerId } = options | ||
const data = { | ||
location_id: locationId, | ||
customer_id: customerId | ||
} | ||
options.success = options.success || function setHomeStore (response) { | ||
const success = JSON.parse(response) | ||
const successEvent = new CustomEvent('homestore:set', { | ||
detail: { | ||
response: success | ||
} | ||
}) | ||
document.dispatchEvent(successEvent) | ||
} | ||
options.error = options.error || this.defaultError | ||
Cookie.set('HomeStore', data, { expires: 365 }) | ||
const request = { | ||
url: `${this.settings.url}/customers/default-location${this.settings.params}`, | ||
success: options.success, | ||
method: 'PUT', | ||
error: options.error, | ||
data: data | ||
} | ||
this.queue.add(request) | ||
return this | ||
@@ -176,3 +203,3 @@ } | ||
const request = { | ||
url: this.settings.url + `/orders/${id}/return` + this.settings.params, | ||
url: `${this.settings.url}/orders/${id}/return${this.settings.params}`, | ||
success: options.success, | ||
@@ -179,0 +206,0 @@ method: 'POST', |
{ | ||
"name": "@dotdev/locations", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Front end store locator api wrapper", | ||
@@ -17,2 +17,3 @@ "browser": "lib/locations.js", | ||
"babel-plugin-transform-es2015-template-literals": "^6.22.0", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"eslint": "^5.6.0", | ||
@@ -19,0 +20,0 @@ "eslint-config-standard": "^12.0.0", |
17230
381
12