@searchspring/snap-store-mobx 0.51.2 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Autocomplete/AutocompleteStore.js +1 -2
- package/dist/cjs/Cart/CartStore.d.ts +15 -0
- package/dist/cjs/Cart/CartStore.d.ts.map +1 -0
- package/dist/cjs/Cart/CartStore.js +104 -0
- package/dist/cjs/Finder/FinderStore.js +1 -2
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts +4 -4
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/cjs/Finder/Stores/FinderSelectionStore.js +1 -2
- package/dist/cjs/Recommendation/RecommendationStore.d.ts +4 -2
- package/dist/cjs/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationStore.js +6 -2
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.d.ts +1 -0
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.d.ts.map +1 -1
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.js +3 -0
- package/dist/cjs/Search/SearchStore.js +1 -2
- package/dist/cjs/Search/Stores/SearchFacetStore.js +4 -4
- package/dist/cjs/Search/Stores/SearchHistoryStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchHistoryStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.js +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts +54 -2
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.js +240 -5
- package/dist/cjs/Search/Stores/SearchSortingStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchSortingStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/index.d.ts +1 -1
- package/dist/cjs/Search/Stores/index.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/index.js +2 -1
- package/dist/cjs/Storage/StorageStore.d.ts +1 -1
- package/dist/cjs/Storage/StorageStore.d.ts.map +1 -1
- package/dist/cjs/Storage/StorageStore.js +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types.d.ts +23 -12
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +1 -1
- package/dist/esm/Cart/CartStore.d.ts +15 -0
- package/dist/esm/Cart/CartStore.d.ts.map +1 -0
- package/dist/esm/Cart/CartStore.js +69 -0
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts +4 -4
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationStore.d.ts +4 -2
- package/dist/esm/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationStore.js +5 -0
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.d.ts +1 -0
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.js +3 -0
- package/dist/esm/Search/Stores/SearchHistoryStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchHistoryStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchMerchandisingStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchMerchandisingStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchResultStore.d.ts +54 -2
- package/dist/esm/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchResultStore.js +207 -2
- package/dist/esm/Search/Stores/SearchSortingStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchSortingStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/index.d.ts +1 -1
- package/dist/esm/Search/Stores/index.d.ts.map +1 -1
- package/dist/esm/Search/Stores/index.js +1 -1
- package/dist/esm/Storage/StorageStore.d.ts +1 -1
- package/dist/esm/Storage/StorageStore.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/types.d.ts +23 -12
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -25,15 +25,29 @@ var __assign = (this && this.__assign) || function () {
|
|
|
25
25
|
};
|
|
26
26
|
return __assign.apply(this, arguments);
|
|
27
27
|
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
28
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Product = exports.Banner = exports.SearchResultStore = void 0;
|
|
41
|
+
exports.VariantSelection = exports.Product = exports.Banner = exports.SearchResultStore = void 0;
|
|
30
42
|
var mobx_1 = require("mobx");
|
|
43
|
+
var deepmerge_1 = __importDefault(require("deepmerge"));
|
|
44
|
+
var is_plain_object_1 = require("is-plain-object");
|
|
31
45
|
var SearchResultStore = /** @class */ (function (_super) {
|
|
32
46
|
__extends(SearchResultStore, _super);
|
|
33
47
|
function SearchResultStore(config, services, resultData, paginationData, merchData) {
|
|
34
48
|
var _a;
|
|
35
49
|
var results = (resultData || []).map(function (result) {
|
|
36
|
-
return new Product(services, result);
|
|
50
|
+
return new Product(services, result, config);
|
|
37
51
|
});
|
|
38
52
|
if ((_a = merchData === null || merchData === void 0 ? void 0 : merchData.content) === null || _a === void 0 ? void 0 : _a.inline) {
|
|
39
53
|
var banners = merchData.content.inline
|
|
@@ -80,8 +94,9 @@ var Banner = /** @class */ (function () {
|
|
|
80
94
|
}());
|
|
81
95
|
exports.Banner = Banner;
|
|
82
96
|
var Product = /** @class */ (function () {
|
|
83
|
-
function Product(services, result) {
|
|
84
|
-
var
|
|
97
|
+
function Product(services, result, config) {
|
|
98
|
+
var _this = this;
|
|
99
|
+
var _a, _b, _c;
|
|
85
100
|
this.type = 'product';
|
|
86
101
|
this.attributes = {};
|
|
87
102
|
this.mappings = {
|
|
@@ -89,18 +104,53 @@ var Product = /** @class */ (function () {
|
|
|
89
104
|
};
|
|
90
105
|
this.custom = {};
|
|
91
106
|
this.children = [];
|
|
107
|
+
this.quantity = 1;
|
|
108
|
+
this.display = {
|
|
109
|
+
mappings: {
|
|
110
|
+
core: {},
|
|
111
|
+
},
|
|
112
|
+
attributes: {},
|
|
113
|
+
options: {},
|
|
114
|
+
};
|
|
115
|
+
this.updateDisplay = function (display) {
|
|
116
|
+
var defaultDisplay = {
|
|
117
|
+
mappings: _this.mappings,
|
|
118
|
+
attributes: _this.attributes,
|
|
119
|
+
options: {},
|
|
120
|
+
};
|
|
121
|
+
var newDisplay = (0, deepmerge_1.default)(defaultDisplay, display || defaultDisplay, { isMergeableObject: is_plain_object_1.isPlainObject });
|
|
122
|
+
if (JSON.stringify(_this.display) !== JSON.stringify(newDisplay)) {
|
|
123
|
+
_this.display = newDisplay;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
92
126
|
this.id = result.id;
|
|
93
127
|
this.attributes = result.attributes;
|
|
94
128
|
this.mappings = result.mappings;
|
|
95
|
-
|
|
129
|
+
//initialize the display
|
|
130
|
+
this.updateDisplay();
|
|
131
|
+
var variantsField = (_b = (_a = config === null || config === void 0 ? void 0 : config.settings) === null || _a === void 0 ? void 0 : _a.variants) === null || _b === void 0 ? void 0 : _b.field;
|
|
132
|
+
if (config && variantsField && this.attributes && this.attributes[variantsField]) {
|
|
133
|
+
try {
|
|
134
|
+
// parse the field (JSON)
|
|
135
|
+
var parsedVariants = JSON.parse(this.attributes[variantsField]);
|
|
136
|
+
this.variants = new Variants(config, services, parsedVariants, this.updateDisplay);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
// failed to parse the variant JSON
|
|
140
|
+
console.error(err, "Invalid variant JSON for product id: ".concat(result.id));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if ((_c = result === null || result === void 0 ? void 0 : result.children) === null || _c === void 0 ? void 0 : _c.length) {
|
|
96
144
|
this.children = result.children.map(function (variant, index) {
|
|
97
145
|
return new Child(services, __assign({ id: "".concat(result.id, "-").concat(index) }, variant));
|
|
98
146
|
});
|
|
99
147
|
}
|
|
100
148
|
(0, mobx_1.makeObservable)(this, {
|
|
101
149
|
id: mobx_1.observable,
|
|
150
|
+
display: mobx_1.observable,
|
|
102
151
|
attributes: mobx_1.observable,
|
|
103
152
|
custom: mobx_1.observable,
|
|
153
|
+
quantity: mobx_1.observable,
|
|
104
154
|
});
|
|
105
155
|
// must set all subo
|
|
106
156
|
var coreObservables = Object.keys(this.mappings.core).reduce(function (map, key) {
|
|
@@ -112,6 +162,191 @@ var Product = /** @class */ (function () {
|
|
|
112
162
|
return Product;
|
|
113
163
|
}());
|
|
114
164
|
exports.Product = Product;
|
|
165
|
+
var Variants = /** @class */ (function () {
|
|
166
|
+
function Variants(config, services, variantData, updateDisplay) {
|
|
167
|
+
var _this = this;
|
|
168
|
+
this.data = [];
|
|
169
|
+
this.selections = [];
|
|
170
|
+
var options = [];
|
|
171
|
+
// create variants objects
|
|
172
|
+
this.data = variantData.map(function (variant) {
|
|
173
|
+
Object.keys(variant.options).forEach(function (variantOption) {
|
|
174
|
+
if (!options.includes(variantOption)) {
|
|
175
|
+
options.push(variantOption);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return new Variant(services, variant);
|
|
179
|
+
});
|
|
180
|
+
this.config = config;
|
|
181
|
+
this.updateDisplay = updateDisplay;
|
|
182
|
+
options.map(function (option) {
|
|
183
|
+
// TODO - merge with variant config before constructing selection (for label overrides and swatch mappings)
|
|
184
|
+
var optionConfig = {
|
|
185
|
+
field: option,
|
|
186
|
+
label: option,
|
|
187
|
+
};
|
|
188
|
+
_this.selections.push(new VariantSelection(config, services, _this, optionConfig, _this.data));
|
|
189
|
+
});
|
|
190
|
+
// select first available
|
|
191
|
+
this.makeSelections();
|
|
192
|
+
}
|
|
193
|
+
Variants.prototype.setActive = function (variant) {
|
|
194
|
+
this.active = variant;
|
|
195
|
+
this.updateDisplay(this.active);
|
|
196
|
+
};
|
|
197
|
+
Variants.prototype.makeSelections = function (options) {
|
|
198
|
+
// TODO - support for affinity to attempt to pre-selected options
|
|
199
|
+
// options = {color: 'Blue', size: 'L'};
|
|
200
|
+
if (!options) {
|
|
201
|
+
// select first available for each selection
|
|
202
|
+
this.selections.forEach(function (selection) {
|
|
203
|
+
var firstAvailableOption = selection.values.find(function (value) { return value.available; });
|
|
204
|
+
if (firstAvailableOption) {
|
|
205
|
+
selection.select(firstAvailableOption.value);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
Variants.prototype.update = function (fromSelection) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
// need to ensure the update originator is at the BOTTOM of the list for refinement
|
|
213
|
+
var orderedSelections = __spreadArray([], this.selections, true);
|
|
214
|
+
orderedSelections.sort(function (a) {
|
|
215
|
+
if (a.field == fromSelection.field) {
|
|
216
|
+
return 1;
|
|
217
|
+
}
|
|
218
|
+
return -1;
|
|
219
|
+
});
|
|
220
|
+
// refine selections ensuring that the selection that triggered the update refines LAST
|
|
221
|
+
orderedSelections.forEach(function (selection) { return selection.refineSelections(_this.data); });
|
|
222
|
+
// check to see if we have enough selections made to update the display
|
|
223
|
+
var selectedSelections = this.selections.filter(function (selection) { var _a; return (_a = selection.selected) === null || _a === void 0 ? void 0 : _a.length; });
|
|
224
|
+
if (selectedSelections.length) {
|
|
225
|
+
var availableVariants = this.data;
|
|
226
|
+
var _loop_1 = function (selectedSelection) {
|
|
227
|
+
availableVariants = availableVariants.filter(function (variant) { return selectedSelection.selected == variant.options[selectedSelection.field] && variant.available; });
|
|
228
|
+
};
|
|
229
|
+
// loop through selectedSelections and only include available products that match current selections
|
|
230
|
+
for (var _i = 0, selectedSelections_1 = selectedSelections; _i < selectedSelections_1.length; _i++) {
|
|
231
|
+
var selectedSelection = selectedSelections_1[_i];
|
|
232
|
+
_loop_1(selectedSelection);
|
|
233
|
+
}
|
|
234
|
+
// set active variant
|
|
235
|
+
if (availableVariants.length == 1) {
|
|
236
|
+
this.setActive(availableVariants[0]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
return Variants;
|
|
241
|
+
}());
|
|
242
|
+
var VariantSelection = /** @class */ (function () {
|
|
243
|
+
function VariantSelection(config, services, variants, selectorConfig, data) {
|
|
244
|
+
this.selected = ''; //ex: blue
|
|
245
|
+
this.previouslySelected = '';
|
|
246
|
+
this.values = [];
|
|
247
|
+
this.field = selectorConfig.field;
|
|
248
|
+
this.label = selectorConfig.label;
|
|
249
|
+
// reference to parent variants
|
|
250
|
+
this.variants = variants;
|
|
251
|
+
// create possible values from the data and refine them
|
|
252
|
+
this.refineSelections(data);
|
|
253
|
+
(0, mobx_1.makeObservable)(this, {
|
|
254
|
+
selected: mobx_1.observable,
|
|
255
|
+
values: mobx_1.observable,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
VariantSelection.prototype.refineSelections = function (allVariants) {
|
|
259
|
+
var _this = this;
|
|
260
|
+
// current selection should only consider OTHER selections for availability
|
|
261
|
+
var selectedSelections = this.variants.selections.filter(function (selection) { return selection.field != _this.field && selection.selected; });
|
|
262
|
+
var availableVariants = allVariants;
|
|
263
|
+
var _loop_2 = function (selectedSelection) {
|
|
264
|
+
availableVariants = availableVariants.filter(function (variant) { return selectedSelection.selected == variant.options[selectedSelection.field] && variant.available; });
|
|
265
|
+
};
|
|
266
|
+
// loop through selectedSelections and remove products that do not match
|
|
267
|
+
for (var _i = 0, selectedSelections_2 = selectedSelections; _i < selectedSelections_2.length; _i++) {
|
|
268
|
+
var selectedSelection = selectedSelections_2[_i];
|
|
269
|
+
_loop_2(selectedSelection);
|
|
270
|
+
}
|
|
271
|
+
var newValues = allVariants
|
|
272
|
+
.filter(function (variant) { return variant.options[_this.field]; })
|
|
273
|
+
.reduce(function (values, variant) {
|
|
274
|
+
var _a;
|
|
275
|
+
if (!values.some(function (val) { return variant.options[_this.field] == val.value; })) {
|
|
276
|
+
values.push({
|
|
277
|
+
value: variant.options[_this.field],
|
|
278
|
+
label: variant.options[_this.field], // TODO - use configurable mappings
|
|
279
|
+
// TODO set background for swatches (via configurable mappings)
|
|
280
|
+
thumbnailImageUrl: (_a = variant.mappings.core) === null || _a === void 0 ? void 0 : _a.thumbnailImageUrl,
|
|
281
|
+
available: Boolean(availableVariants.some(function (availableVariant) { return availableVariant.options[_this.field] == variant.options[_this.field]; })),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return values;
|
|
285
|
+
}, []);
|
|
286
|
+
// if selection has been made
|
|
287
|
+
if (this.selected) {
|
|
288
|
+
//is that selection still available?
|
|
289
|
+
if (!newValues.some(function (val) { return val.value == _this.selected && val.available; })) {
|
|
290
|
+
// the previous selection is no longer available
|
|
291
|
+
if (this.previouslySelected && newValues.some(function (val) { return val.value == _this.previouslySelected && val.available; })) {
|
|
292
|
+
if (this.selected !== this.previouslySelected) {
|
|
293
|
+
this.select(this.previouslySelected, true);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
//otherwise just choose the first available option
|
|
298
|
+
var availableValues = newValues.filter(function (val) { return val.available; });
|
|
299
|
+
if (newValues.length && availableValues.length) {
|
|
300
|
+
var nextAvailableValue = availableValues[0].value;
|
|
301
|
+
if (this.selected !== nextAvailableValue) {
|
|
302
|
+
this.select(nextAvailableValue, true);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this.values = newValues;
|
|
309
|
+
};
|
|
310
|
+
VariantSelection.prototype.reset = function () {
|
|
311
|
+
this.selected = '';
|
|
312
|
+
this.values.forEach(function (val) { return (val.available = false); });
|
|
313
|
+
};
|
|
314
|
+
VariantSelection.prototype.select = function (value, internalSelection) {
|
|
315
|
+
if (internalSelection === void 0) { internalSelection = false; }
|
|
316
|
+
var valueExist = this.values.find(function (val) { return val.value == value; });
|
|
317
|
+
if (valueExist) {
|
|
318
|
+
this.selected = value;
|
|
319
|
+
if (!internalSelection) {
|
|
320
|
+
this.previouslySelected = value;
|
|
321
|
+
}
|
|
322
|
+
this.variants.update(this);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
return VariantSelection;
|
|
326
|
+
}());
|
|
327
|
+
exports.VariantSelection = VariantSelection;
|
|
328
|
+
var Variant = /** @class */ (function () {
|
|
329
|
+
function Variant(services, variantData) {
|
|
330
|
+
this.type = 'variant';
|
|
331
|
+
this.attributes = {};
|
|
332
|
+
this.options = {};
|
|
333
|
+
this.mappings = {
|
|
334
|
+
core: {},
|
|
335
|
+
};
|
|
336
|
+
this.custom = {};
|
|
337
|
+
this.attributes = variantData.attributes;
|
|
338
|
+
this.mappings = variantData.mappings;
|
|
339
|
+
this.options = variantData.options;
|
|
340
|
+
this.available = this.attributes.available || false;
|
|
341
|
+
(0, mobx_1.makeObservable)(this, {
|
|
342
|
+
attributes: mobx_1.observable,
|
|
343
|
+
mappings: mobx_1.observable,
|
|
344
|
+
custom: mobx_1.observable,
|
|
345
|
+
available: mobx_1.observable,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return Variant;
|
|
349
|
+
}());
|
|
115
350
|
var Child = /** @class */ (function () {
|
|
116
351
|
function Child(services, result) {
|
|
117
352
|
this.type = 'child';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UrlManager } from '@searchspring/snap-url-manager';
|
|
2
2
|
import type { StoreServices } from '../../types';
|
|
3
3
|
import type { MetaResponseModel, MetaResponseModelSortOption, SearchResponseModelSearch, SearchResponseModelSorting } from '@searchspring/snapi-types';
|
|
4
|
-
|
|
4
|
+
type MetaResponseModelSortOptionMutated = MetaResponseModelSortOption & {
|
|
5
5
|
active?: boolean;
|
|
6
6
|
default?: boolean;
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchSortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchSortingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,
|
|
1
|
+
{"version":3,"file":"SearchSortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchSortingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,KAAK,kCAAkC,GAAG,2BAA2B,GAAG;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,qBAAa,kBAAkB;IACvB,OAAO,EAAE,MAAM,EAAE,CAAM;gBAElB,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,0BAA0B,EAAE,EAAE,MAAM,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB;IAsCtI,IAAW,OAAO,IAAI,MAAM,GAAG,SAAS,CAEvC;CACD;AAED,cAAM,MAAM;IACJ,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,UAAU,CAAC;gBAEX,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,kCAAkC,EAAE,KAAK,EAAE,MAAM;CAuB9F"}
|
|
@@ -2,7 +2,7 @@ export { SearchMerchandisingStore, BannerContent, ContentType } from './SearchMe
|
|
|
2
2
|
export { SearchFacetStore, ValueFacet, RangeFacet, FacetValue, FacetHierarchyValue, FacetRangeValue } from './SearchFacetStore';
|
|
3
3
|
export { SearchFilterStore, Filter } from './SearchFilterStore';
|
|
4
4
|
export { SearchPaginationStore } from './SearchPaginationStore';
|
|
5
|
-
export { SearchResultStore, Product, Banner } from './SearchResultStore';
|
|
5
|
+
export { SearchResultStore, Product, Banner, VariantSelection } from './SearchResultStore';
|
|
6
6
|
export { SearchSortingStore } from './SearchSortingStore';
|
|
7
7
|
export { SearchQueryStore } from './SearchQueryStore';
|
|
8
8
|
export { SearchHistoryStore } from './SearchHistoryStore';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchHistoryStore = exports.SearchQueryStore = exports.SearchSortingStore = exports.Banner = exports.Product = exports.SearchResultStore = exports.SearchPaginationStore = exports.Filter = exports.SearchFilterStore = exports.FacetRangeValue = exports.FacetHierarchyValue = exports.FacetValue = exports.RangeFacet = exports.ValueFacet = exports.SearchFacetStore = exports.ContentType = exports.SearchMerchandisingStore = void 0;
|
|
3
|
+
exports.SearchHistoryStore = exports.SearchQueryStore = exports.SearchSortingStore = exports.VariantSelection = exports.Banner = exports.Product = exports.SearchResultStore = exports.SearchPaginationStore = exports.Filter = exports.SearchFilterStore = exports.FacetRangeValue = exports.FacetHierarchyValue = exports.FacetValue = exports.RangeFacet = exports.ValueFacet = exports.SearchFacetStore = exports.ContentType = exports.SearchMerchandisingStore = void 0;
|
|
4
4
|
var SearchMerchandisingStore_1 = require("./SearchMerchandisingStore");
|
|
5
5
|
Object.defineProperty(exports, "SearchMerchandisingStore", { enumerable: true, get: function () { return SearchMerchandisingStore_1.SearchMerchandisingStore; } });
|
|
6
6
|
Object.defineProperty(exports, "ContentType", { enumerable: true, get: function () { return SearchMerchandisingStore_1.ContentType; } });
|
|
@@ -20,6 +20,7 @@ var SearchResultStore_1 = require("./SearchResultStore");
|
|
|
20
20
|
Object.defineProperty(exports, "SearchResultStore", { enumerable: true, get: function () { return SearchResultStore_1.SearchResultStore; } });
|
|
21
21
|
Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return SearchResultStore_1.Product; } });
|
|
22
22
|
Object.defineProperty(exports, "Banner", { enumerable: true, get: function () { return SearchResultStore_1.Banner; } });
|
|
23
|
+
Object.defineProperty(exports, "VariantSelection", { enumerable: true, get: function () { return SearchResultStore_1.VariantSelection; } });
|
|
23
24
|
var SearchSortingStore_1 = require("./SearchSortingStore");
|
|
24
25
|
Object.defineProperty(exports, "SearchSortingStore", { enumerable: true, get: function () { return SearchSortingStore_1.SearchSortingStore; } });
|
|
25
26
|
var SearchQueryStore_1 = require("./SearchQueryStore");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAgB;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAE3B,MAAM,CAAC,EAAE,aAAa;IA8C3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAiClC,KAAK,IAAI,IAAI;CAcpB;AAED,
|
|
1
|
+
{"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAgB;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAE3B,MAAM,CAAC,EAAE,aAAa;IA8C3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAiClC,KAAK,IAAI,IAAI;CAcpB;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,oBAAY,WAAW;IACtB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;CACjB"}
|
|
@@ -136,4 +136,4 @@ var StorageType;
|
|
|
136
136
|
StorageType["LOCAL"] = "local";
|
|
137
137
|
StorageType["COOKIE"] = "cookie";
|
|
138
138
|
StorageType["MEMORY"] = "memory";
|
|
139
|
-
})(StorageType
|
|
139
|
+
})(StorageType || (exports.StorageType = StorageType = {}));
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { FinderStore } from './Finder/FinderStore';
|
|
|
4
4
|
export { SearchStore } from './Search/SearchStore';
|
|
5
5
|
export * from './Search/Stores/';
|
|
6
6
|
export { RecommendationStore } from './Recommendation/RecommendationStore';
|
|
7
|
+
export { CartStore } from './Cart/CartStore';
|
|
7
8
|
export { StorageStore, StorageConfig, StorageType } from './Storage/StorageStore';
|
|
8
9
|
export * from './types';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAElF,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAElF,cAAc,SAAS,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.StorageType = exports.StorageStore = exports.RecommendationStore = exports.SearchStore = exports.FinderStore = exports.AutocompleteStore = exports.AbstractStore = void 0;
|
|
17
|
+
exports.StorageType = exports.StorageStore = exports.CartStore = exports.RecommendationStore = exports.SearchStore = exports.FinderStore = exports.AutocompleteStore = exports.AbstractStore = void 0;
|
|
18
18
|
var AbstractStore_1 = require("./Abstract/AbstractStore");
|
|
19
19
|
Object.defineProperty(exports, "AbstractStore", { enumerable: true, get: function () { return AbstractStore_1.AbstractStore; } });
|
|
20
20
|
var AutocompleteStore_1 = require("./Autocomplete/AutocompleteStore");
|
|
@@ -26,6 +26,8 @@ Object.defineProperty(exports, "SearchStore", { enumerable: true, get: function
|
|
|
26
26
|
__exportStar(require("./Search/Stores/"), exports);
|
|
27
27
|
var RecommendationStore_1 = require("./Recommendation/RecommendationStore");
|
|
28
28
|
Object.defineProperty(exports, "RecommendationStore", { enumerable: true, get: function () { return RecommendationStore_1.RecommendationStore; } });
|
|
29
|
+
var CartStore_1 = require("./Cart/CartStore");
|
|
30
|
+
Object.defineProperty(exports, "CartStore", { enumerable: true, get: function () { return CartStore_1.CartStore; } });
|
|
29
31
|
var StorageStore_1 = require("./Storage/StorageStore");
|
|
30
32
|
Object.defineProperty(exports, "StorageStore", { enumerable: true, get: function () { return StorageStore_1.StorageStore; } });
|
|
31
33
|
Object.defineProperty(exports, "StorageType", { enumerable: true, get: function () { return StorageStore_1.StorageType; } });
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { UrlManager } from '@searchspring/snap-url-manager';
|
|
2
2
|
import type { SearchResponseModelFacetValueAllOfValues, AutocompleteRequestModel, SearchRequestModel } from '@searchspring/snapi-types';
|
|
3
|
-
export
|
|
3
|
+
export type StoreConfig = {
|
|
4
4
|
id: string;
|
|
5
5
|
[any: string]: unknown;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type VariantConfig = {
|
|
8
|
+
field: string;
|
|
9
|
+
};
|
|
10
|
+
export type VariantSelectionOptions = {
|
|
11
|
+
field: string;
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
export type SearchStoreConfig = StoreConfig & {
|
|
8
15
|
globals?: Partial<SearchRequestModel>;
|
|
9
16
|
settings?: {
|
|
10
17
|
redirects?: {
|
|
@@ -23,6 +30,7 @@ export declare type SearchStoreConfig = StoreConfig & {
|
|
|
23
30
|
enabled: boolean;
|
|
24
31
|
onPageShow?: boolean;
|
|
25
32
|
};
|
|
33
|
+
variants?: VariantConfig;
|
|
26
34
|
history?: {
|
|
27
35
|
url?: string;
|
|
28
36
|
max?: number;
|
|
@@ -35,13 +43,13 @@ export declare type SearchStoreConfig = StoreConfig & {
|
|
|
35
43
|
};
|
|
36
44
|
};
|
|
37
45
|
};
|
|
38
|
-
export
|
|
46
|
+
export type FacetStoreConfig = {
|
|
39
47
|
trim?: boolean;
|
|
40
48
|
pinFiltered?: boolean;
|
|
41
49
|
storeRange?: boolean;
|
|
42
50
|
autoOpenActive?: boolean;
|
|
43
51
|
};
|
|
44
|
-
export
|
|
52
|
+
export type FinderStoreConfig = StoreConfig & {
|
|
45
53
|
globals?: any;
|
|
46
54
|
url?: string;
|
|
47
55
|
fields: FinderFieldConfig[];
|
|
@@ -51,12 +59,12 @@ export declare type FinderStoreConfig = StoreConfig & {
|
|
|
51
59
|
expiration?: number;
|
|
52
60
|
};
|
|
53
61
|
};
|
|
54
|
-
export
|
|
62
|
+
export type FinderFieldConfig = {
|
|
55
63
|
field: string;
|
|
56
64
|
label?: string;
|
|
57
65
|
levels?: string[];
|
|
58
66
|
};
|
|
59
|
-
export
|
|
67
|
+
export type AutocompleteStoreConfigSettings = {
|
|
60
68
|
integratedSpellCorrection?: boolean;
|
|
61
69
|
initializeFromUrl?: boolean;
|
|
62
70
|
syncInputs?: boolean;
|
|
@@ -70,6 +78,7 @@ export declare type AutocompleteStoreConfigSettings = {
|
|
|
70
78
|
limit: number;
|
|
71
79
|
showResults?: boolean;
|
|
72
80
|
};
|
|
81
|
+
variants?: VariantConfig;
|
|
73
82
|
history?: {
|
|
74
83
|
limit: number;
|
|
75
84
|
showResults?: boolean;
|
|
@@ -79,22 +88,23 @@ export declare type AutocompleteStoreConfigSettings = {
|
|
|
79
88
|
singleResult?: boolean;
|
|
80
89
|
};
|
|
81
90
|
};
|
|
82
|
-
export
|
|
91
|
+
export type AutocompleteStoreConfig = StoreConfig & {
|
|
83
92
|
globals?: Partial<AutocompleteRequestModel>;
|
|
84
93
|
selector: string;
|
|
85
94
|
action?: string;
|
|
86
95
|
settings?: AutocompleteStoreConfigSettings;
|
|
87
96
|
};
|
|
88
|
-
export
|
|
97
|
+
export type RecommendationStoreConfig = StoreConfig & {
|
|
89
98
|
globals?: any;
|
|
90
99
|
tag: string;
|
|
91
100
|
branch?: string;
|
|
92
101
|
realtime?: boolean;
|
|
93
102
|
batched?: boolean;
|
|
94
103
|
order?: number;
|
|
104
|
+
variants?: VariantConfig;
|
|
95
105
|
};
|
|
96
|
-
export
|
|
97
|
-
export
|
|
106
|
+
export type StoreConfigs = SearchStoreConfig | AutocompleteStoreConfig | FinderStoreConfig | RecommendationStoreConfig;
|
|
107
|
+
export type StoreServices = {
|
|
98
108
|
urlManager: UrlManager;
|
|
99
109
|
};
|
|
100
110
|
export declare enum ErrorType {
|
|
@@ -102,12 +112,13 @@ export declare enum ErrorType {
|
|
|
102
112
|
INFO = "info",
|
|
103
113
|
ERROR = "error"
|
|
104
114
|
}
|
|
105
|
-
export
|
|
115
|
+
export type SelectedSelection = {
|
|
106
116
|
selected: string;
|
|
107
117
|
data: SearchResponseModelFacetValueAllOfValues[];
|
|
108
118
|
facet: any;
|
|
109
119
|
};
|
|
110
|
-
export
|
|
120
|
+
export type FinderStoreState = {
|
|
111
121
|
persisted: boolean;
|
|
112
122
|
};
|
|
123
|
+
export {};
|
|
113
124
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,wCAAwC,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAExI,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/cjs/types.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Middleware } from '@searchspring/snap-event-manager';
|
|
2
|
+
import type { Product } from '../Search/Stores';
|
|
3
|
+
export declare class CartStore {
|
|
4
|
+
items: Product[];
|
|
5
|
+
private eventManager;
|
|
6
|
+
constructor();
|
|
7
|
+
on<T>(event: string, ...func: Middleware<T>[]): void;
|
|
8
|
+
get count(): number;
|
|
9
|
+
get price(): number;
|
|
10
|
+
get msrp(): number;
|
|
11
|
+
addItems(items: Product[]): void;
|
|
12
|
+
removeItems(items: Product[]): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CartStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartStore.d.ts","sourceRoot":"","sources":["../../../src/Cart/CartStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,qBAAa,SAAS;IACd,KAAK,EAAE,OAAO,EAAE,CAAM;IAC7B,OAAO,CAAC,YAAY,CAAC;;IAYd,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAI3D,IAAI,KAAK,IAAI,MAAM,CAMlB;IAED,IAAI,KAAK,IAAI,MAAM,CAMlB;IAED,IAAI,IAAI,IAAI,MAAM,CAMjB;IAEM,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAahC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAsBnC,KAAK,IAAI,IAAI;CAIpB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { observable, computed, makeObservable } from 'mobx';
|
|
2
|
+
import { EventManager } from '@searchspring/snap-event-manager';
|
|
3
|
+
export class CartStore {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.items = [];
|
|
6
|
+
makeObservable(this, {
|
|
7
|
+
items: observable,
|
|
8
|
+
price: computed,
|
|
9
|
+
count: computed,
|
|
10
|
+
msrp: computed,
|
|
11
|
+
});
|
|
12
|
+
this.eventManager = new EventManager();
|
|
13
|
+
}
|
|
14
|
+
on(event, ...func) {
|
|
15
|
+
this.eventManager.on(event, ...func);
|
|
16
|
+
}
|
|
17
|
+
get count() {
|
|
18
|
+
let count = 0;
|
|
19
|
+
this.items.forEach((item) => {
|
|
20
|
+
count += item.quantity;
|
|
21
|
+
});
|
|
22
|
+
return count;
|
|
23
|
+
}
|
|
24
|
+
get price() {
|
|
25
|
+
let price = 0;
|
|
26
|
+
this.items.forEach((item) => {
|
|
27
|
+
price += (item.display.mappings.core?.price || 0) * item.quantity;
|
|
28
|
+
});
|
|
29
|
+
return price;
|
|
30
|
+
}
|
|
31
|
+
get msrp() {
|
|
32
|
+
let price = 0;
|
|
33
|
+
this.items.forEach((item) => {
|
|
34
|
+
price += (item.display.mappings.core?.msrp || item.display.mappings.core?.price || 0) * item.quantity;
|
|
35
|
+
});
|
|
36
|
+
return price;
|
|
37
|
+
}
|
|
38
|
+
addItems(items) {
|
|
39
|
+
items.forEach((item) => {
|
|
40
|
+
const idx = this.items.findIndex((result) => result.id == item.id);
|
|
41
|
+
//is it in the items list?
|
|
42
|
+
if (idx == -1) {
|
|
43
|
+
this.items.push(item);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.eventManager.fire('addItems', { cart: this, items });
|
|
47
|
+
}
|
|
48
|
+
removeItems(items) {
|
|
49
|
+
const newIds = [...this.items];
|
|
50
|
+
items.forEach((item) => {
|
|
51
|
+
const idx = newIds.findIndex((result) => result.id == item.id);
|
|
52
|
+
//is it in the selected items?
|
|
53
|
+
if (idx > -1) {
|
|
54
|
+
// remove it entirely
|
|
55
|
+
newIds.splice(idx, 1);
|
|
56
|
+
// when emptied fire empty event
|
|
57
|
+
if (newIds.length == 0) {
|
|
58
|
+
this.eventManager.fire('emptied', { cart: this });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
this.items = newIds;
|
|
63
|
+
this.eventManager.fire('removeItems', { cart: this, items });
|
|
64
|
+
}
|
|
65
|
+
reset() {
|
|
66
|
+
this.items = [];
|
|
67
|
+
this.eventManager.fire('reset', { cart: this });
|
|
68
|
+
}
|
|
69
|
+
}
|