@pisell/pisellos 2.3.150 → 2.3.151
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/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
- package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/dist/model/strategy/adapter/itemRule/type.js +10 -0
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/OpenData/types.d.ts +2 -0
- package/dist/modules/Order/index.d.ts +4 -2
- package/dist/modules/Order/index.js +115 -67
- package/dist/modules/Order/types.d.ts +7 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
- package/dist/solution/BaseSales/index.d.ts +5 -1
- package/dist/solution/BaseSales/index.js +1116 -1021
- package/dist/solution/BaseSales/pickupTiming.d.ts +2 -0
- package/dist/solution/BaseSales/pickupTiming.js +16 -5
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -0
- package/dist/solution/BookingTicket/index.js +444 -425
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
- package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
- package/lib/model/strategy/adapter/itemRule/type.js +10 -0
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/OpenData/types.d.ts +2 -0
- package/lib/modules/Order/index.d.ts +4 -2
- package/lib/modules/Order/index.js +33 -14
- package/lib/modules/Order/types.d.ts +7 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
- package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
- package/lib/solution/BaseSales/index.d.ts +5 -1
- package/lib/solution/BaseSales/index.js +38 -2
- package/lib/solution/BaseSales/pickupTiming.d.ts +2 -0
- package/lib/solution/BaseSales/pickupTiming.js +5 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -0
- package/lib/solution/BookingTicket/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
18
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
19
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
22
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
23
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
24
|
+
import dayjs from 'dayjs';
|
|
25
|
+
import { ItemRuleEvaluator } from "../../model/strategy/adapter/itemRule";
|
|
26
|
+
import { transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
|
|
27
|
+
var ownershipField = 'fulfillment_item_rule';
|
|
28
|
+
function positiveIds(value) {
|
|
29
|
+
if (!Array.isArray(value)) return [];
|
|
30
|
+
return _toConsumableArray(new Set(value.map(Number).filter(function (id) {
|
|
31
|
+
return Number.isInteger(id) && id > 0;
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
function lineIdentity(line) {
|
|
35
|
+
var _line$metadata;
|
|
36
|
+
return {
|
|
37
|
+
product_id: line.product_id,
|
|
38
|
+
product_variant_id: line.product_variant_id,
|
|
39
|
+
unique_identification_number: ((_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.unique_identification_number) || line.unique_identification_number,
|
|
40
|
+
product_sku: line.product_sku,
|
|
41
|
+
product_bundle: line.product_bundle
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function cartFingerprint(lines) {
|
|
45
|
+
return JSON.stringify(lines.map(function (line) {
|
|
46
|
+
var _line$metadata2;
|
|
47
|
+
return [lineIdentity(line), line.num, (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2[ownershipField]];
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
function selectionFingerprint(lines, excludedIds) {
|
|
51
|
+
var quantities = new Map();
|
|
52
|
+
var _iterator = _createForOfIteratorHelper(lines),
|
|
53
|
+
_step;
|
|
54
|
+
try {
|
|
55
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
56
|
+
var _line$metadata3;
|
|
57
|
+
var line = _step.value;
|
|
58
|
+
if (excludedIds.has(Number(line.product_id)) || (_line$metadata3 = line.metadata) !== null && _line$metadata3 !== void 0 && _line$metadata3._giftInfo) continue;
|
|
59
|
+
var key = JSON.stringify([Number(line.product_id), Number(line.product_variant_id) || 0]);
|
|
60
|
+
quantities.set(key, (quantities.get(key) || 0) + Number(line.num || 0));
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_iterator.e(err);
|
|
64
|
+
} finally {
|
|
65
|
+
_iterator.f();
|
|
66
|
+
}
|
|
67
|
+
return JSON.stringify(_toConsumableArray(quantities).sort(function (_ref, _ref2) {
|
|
68
|
+
var _ref3 = _slicedToArray(_ref, 1),
|
|
69
|
+
left = _ref3[0];
|
|
70
|
+
var _ref4 = _slicedToArray(_ref2, 1),
|
|
71
|
+
right = _ref4[0];
|
|
72
|
+
return left.localeCompare(right);
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
function ownerKey(action, product) {
|
|
76
|
+
var _product$product_vari;
|
|
77
|
+
return JSON.stringify([action.strategyId, action.ruleId, product.product_id, (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0]);
|
|
78
|
+
}
|
|
79
|
+
function ownedLines(lines, key) {
|
|
80
|
+
return lines.filter(function (line) {
|
|
81
|
+
var _line$metadata4;
|
|
82
|
+
return ((_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4[ownershipField]) === key;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Executes item rules at the sales boundary, independent of the calling template. */
|
|
87
|
+
export var FulfillmentItemRulesController = /*#__PURE__*/function () {
|
|
88
|
+
function FulfillmentItemRulesController(host) {
|
|
89
|
+
_classCallCheck(this, FulfillmentItemRulesController);
|
|
90
|
+
_defineProperty(this, "sequence", 0);
|
|
91
|
+
_defineProperty(this, "pending", Promise.resolve());
|
|
92
|
+
_defineProperty(this, "evaluator", new ItemRuleEvaluator());
|
|
93
|
+
this.host = host;
|
|
94
|
+
}
|
|
95
|
+
_createClass(FulfillmentItemRulesController, [{
|
|
96
|
+
key: "invalidate",
|
|
97
|
+
value: function invalidate() {
|
|
98
|
+
this.sequence += 1;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "apply",
|
|
102
|
+
value: function apply(serviceType) {
|
|
103
|
+
var _order$getTempOrder,
|
|
104
|
+
_this = this;
|
|
105
|
+
var sequence = ++this.sequence;
|
|
106
|
+
// Even an unsupported mode supersedes any pending takeaway operation.
|
|
107
|
+
if (serviceType !== 'takeaway' && serviceType !== 'dine_in') return Promise.resolve();
|
|
108
|
+
var order = this.host.getOrder();
|
|
109
|
+
var tempOrder = (_order$getTempOrder = order.getTempOrder) === null || _order$getTempOrder === void 0 ? void 0 : _order$getTempOrder.call(order);
|
|
110
|
+
var scope = this.host.getScope();
|
|
111
|
+
var identity = JSON.stringify([tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id, tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number, tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id]);
|
|
112
|
+
var initialProducts = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products;
|
|
113
|
+
var initialFingerprint = cartFingerprint(initialProducts || []);
|
|
114
|
+
var isCurrent = function isCurrent() {
|
|
115
|
+
var _order$getTempOrder2, _tempOrder$metadata;
|
|
116
|
+
return sequence === _this.sequence && scope === _this.host.getScope() && _this.host.getOrder() === order && ((_order$getTempOrder2 = order.getTempOrder) === null || _order$getTempOrder2 === void 0 ? void 0 : _order$getTempOrder2.call(order)) === tempOrder && identity === JSON.stringify([tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id, tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number, tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id]) && (tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 || (_tempOrder$metadata = _tempOrder$metadata.shop_service_data) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.service_type) === serviceType;
|
|
117
|
+
};
|
|
118
|
+
var run = /*#__PURE__*/function () {
|
|
119
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
120
|
+
var _response$data, _runtime$itemRule, _ref6, _runtime$channel, _runtime$itemRule2;
|
|
121
|
+
var openData, ids, assertSnapshot, response, configs, runtime, pax, businessData, initialEvaluation, requiresMainQuantity, actions, sources, targetIds, originalSelection, targetIsCurrent, _iterator2, _step2, _loop, _ret;
|
|
122
|
+
return _regeneratorRuntime().wrap(function _callee$(_context3) {
|
|
123
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
124
|
+
case 0:
|
|
125
|
+
_context3.next = 2;
|
|
126
|
+
return _this.host.loadOpenData();
|
|
127
|
+
case 2:
|
|
128
|
+
openData = _context3.sent;
|
|
129
|
+
ids = positiveIds(openData === null || openData === void 0 ? void 0 : openData["fulfillment.".concat(serviceType, "_fees_rules")]);
|
|
130
|
+
if (!(!ids.length || !isCurrent())) {
|
|
131
|
+
_context3.next = 6;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return _context3.abrupt("return");
|
|
135
|
+
case 6:
|
|
136
|
+
if (tempOrder) {
|
|
137
|
+
_context3.next = 8;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return _context3.abrupt("return");
|
|
141
|
+
case 8:
|
|
142
|
+
assertSnapshot = function assertSnapshot() {
|
|
143
|
+
if (!isCurrent() || tempOrder.products !== initialProducts || cartFingerprint(tempOrder.products) !== initialFingerprint) {
|
|
144
|
+
throw new Error('The order changed while preparing fulfillment item rules');
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
assertSnapshot();
|
|
148
|
+
_context3.next = 12;
|
|
149
|
+
return _this.host.fetchStrategyModels(ids);
|
|
150
|
+
case 12:
|
|
151
|
+
response = _context3.sent;
|
|
152
|
+
assertSnapshot();
|
|
153
|
+
if (!((response === null || response === void 0 ? void 0 : response.code) !== 200 || !Array.isArray(response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list))) {
|
|
154
|
+
_context3.next = 16;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
throw new Error('Unable to load fulfillment item rules');
|
|
158
|
+
case 16:
|
|
159
|
+
// Response order need not match the configured order (the latter breaks priority ties).
|
|
160
|
+
configs = ids.map(function (id) {
|
|
161
|
+
var _response$data$list$f, _config$metadata;
|
|
162
|
+
var config = (_response$data$list$f = response.data.list.find(function (item) {
|
|
163
|
+
return Number(item === null || item === void 0 ? void 0 : item.id) === id;
|
|
164
|
+
})) === null || _response$data$list$f === void 0 ? void 0 : _response$data$list$f.metadata;
|
|
165
|
+
if ((config === null || config === void 0 || (_config$metadata = config.metadata) === null || _config$metadata === void 0 ? void 0 : _config$metadata.type) !== 'item_rule' || !Array.isArray(config.actions) || !config.conditions) {
|
|
166
|
+
throw new Error("Invalid or missing fulfillment item rule ".concat(id));
|
|
167
|
+
}
|
|
168
|
+
return config;
|
|
169
|
+
});
|
|
170
|
+
runtime = _this.host.getOtherParams();
|
|
171
|
+
pax = ((_runtime$itemRule = runtime.itemRule) === null || _runtime$itemRule === void 0 ? void 0 : _runtime$itemRule.pax) || {};
|
|
172
|
+
businessData = {
|
|
173
|
+
executionScope: 'set_handover',
|
|
174
|
+
serviceType: serviceType,
|
|
175
|
+
channel: String((_ref6 = (_runtime$channel = runtime.channel) !== null && _runtime$channel !== void 0 ? _runtime$channel : runtime.platform) !== null && _ref6 !== void 0 ? _ref6 : ''),
|
|
176
|
+
pax: {
|
|
177
|
+
total: Number(pax.total) || 0,
|
|
178
|
+
adult: Number(pax.adult) || 0,
|
|
179
|
+
child: Number(pax.child) || 0
|
|
180
|
+
},
|
|
181
|
+
cartItems: tempOrder.products.map(function (line) {
|
|
182
|
+
return {
|
|
183
|
+
product_id: Number(line.product_id),
|
|
184
|
+
product_variant_id: Number(line.product_variant_id) || 0,
|
|
185
|
+
quantity: Number(line.num) || 0
|
|
186
|
+
};
|
|
187
|
+
}),
|
|
188
|
+
strategyConfigs: configs,
|
|
189
|
+
custom: (_runtime$itemRule2 = runtime.itemRule) === null || _runtime$itemRule2 === void 0 ? void 0 : _runtime$itemRule2.custom
|
|
190
|
+
};
|
|
191
|
+
initialEvaluation = _this.evaluator.evaluate(businessData);
|
|
192
|
+
requiresMainQuantity = initialEvaluation.rawResults.some(function (result) {
|
|
193
|
+
return result.applicable && result.matchedActions.some(function (action) {
|
|
194
|
+
var _action$config, _action$config$produc;
|
|
195
|
+
return action.type === 'PREFILL_CART' && action.target === 'cart' && ((_action$config = action.config) === null || _action$config === void 0 ? void 0 : _action$config.scope) === 'set_handover' && ((_action$config$produc = action.config.products) === null || _action$config$produc === void 0 ? void 0 : _action$config$produc.some(function (product) {
|
|
196
|
+
return product.quantityFrom === 'main_product_number';
|
|
197
|
+
}));
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
if (!requiresMainQuantity) {
|
|
201
|
+
_context3.next = 35;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
_context3.t1 = _this.evaluator;
|
|
205
|
+
_context3.t2 = _objectSpread;
|
|
206
|
+
_context3.t3 = _objectSpread({}, businessData);
|
|
207
|
+
_context3.t4 = {};
|
|
208
|
+
_context3.next = 29;
|
|
209
|
+
return _this.getMainProductNumber(tempOrder.products, configs);
|
|
210
|
+
case 29:
|
|
211
|
+
_context3.t5 = _context3.sent;
|
|
212
|
+
_context3.t6 = {
|
|
213
|
+
mainProductNumber: _context3.t5
|
|
214
|
+
};
|
|
215
|
+
_context3.t7 = (0, _context3.t2)(_context3.t3, _context3.t4, _context3.t6);
|
|
216
|
+
_context3.t0 = _context3.t1.evaluate.call(_context3.t1, _context3.t7).cartActions;
|
|
217
|
+
_context3.next = 36;
|
|
218
|
+
break;
|
|
219
|
+
case 35:
|
|
220
|
+
_context3.t0 = initialEvaluation.cartActions;
|
|
221
|
+
case 36:
|
|
222
|
+
actions = _context3.t0;
|
|
223
|
+
assertSnapshot();
|
|
224
|
+
// Prepare every addition before changing the cart; missing products must not leave a half-loaded batch.
|
|
225
|
+
_context3.next = 40;
|
|
226
|
+
return _this.loadPrefillSources(actions, tempOrder.products);
|
|
227
|
+
case 40:
|
|
228
|
+
sources = _context3.sent;
|
|
229
|
+
assertSnapshot();
|
|
230
|
+
targetIds = new Set(actions.flatMap(function (action) {
|
|
231
|
+
return action.products.map(function (product) {
|
|
232
|
+
return Number(product.product_id);
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
235
|
+
originalSelection = selectionFingerprint(tempOrder.products, targetIds); // Promotion may add gifts or split/merge rows. Only a change to the purchased
|
|
236
|
+
// quantities invalidates this selection, not promotion's own line reshaping.
|
|
237
|
+
targetIsCurrent = function targetIsCurrent() {
|
|
238
|
+
return isCurrent() && selectionFingerprint(tempOrder.products, targetIds) === originalSelection;
|
|
239
|
+
};
|
|
240
|
+
_iterator2 = _createForOfIteratorHelper(actions);
|
|
241
|
+
_context3.prev = 46;
|
|
242
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
243
|
+
var action, deletedIds, lines, _iterator3, _step3, _loop2, _ret2;
|
|
244
|
+
return _regeneratorRuntime().wrap(function _loop$(_context2) {
|
|
245
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
246
|
+
case 0:
|
|
247
|
+
action = _step2.value;
|
|
248
|
+
if (targetIsCurrent()) {
|
|
249
|
+
_context2.next = 3;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
return _context2.abrupt("return", {
|
|
253
|
+
v: void 0
|
|
254
|
+
});
|
|
255
|
+
case 3:
|
|
256
|
+
if (!(action.type === 'DELETE_PRODUCT')) {
|
|
257
|
+
_context2.next = 10;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
deletedIds = new Set(action.products.map(function (product) {
|
|
261
|
+
return Number(product.product_id);
|
|
262
|
+
}));
|
|
263
|
+
lines = tempOrder.products.filter(function (line) {
|
|
264
|
+
return deletedIds.has(Number(line.product_id));
|
|
265
|
+
});
|
|
266
|
+
if (!lines.length) {
|
|
267
|
+
_context2.next = 9;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
_context2.next = 9;
|
|
271
|
+
return order.removeProductsFromOrder(lines.map(lineIdentity), {
|
|
272
|
+
isCurrentOrder: targetIsCurrent
|
|
273
|
+
});
|
|
274
|
+
case 9:
|
|
275
|
+
return _context2.abrupt("return", 0);
|
|
276
|
+
case 10:
|
|
277
|
+
_iterator3 = _createForOfIteratorHelper(action.products);
|
|
278
|
+
_context2.prev = 11;
|
|
279
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
|
|
280
|
+
var _product$product_vari2;
|
|
281
|
+
var product, key, existing, quantity, source, line, beforeProducts, beforeFingerprint;
|
|
282
|
+
return _regeneratorRuntime().wrap(function _loop2$(_context) {
|
|
283
|
+
while (1) switch (_context.prev = _context.next) {
|
|
284
|
+
case 0:
|
|
285
|
+
product = _step3.value;
|
|
286
|
+
if (targetIsCurrent()) {
|
|
287
|
+
_context.next = 3;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
return _context.abrupt("return", {
|
|
291
|
+
v: {
|
|
292
|
+
v: void 0
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
case 3:
|
|
296
|
+
key = ownerKey(action, product);
|
|
297
|
+
existing = ownedLines(tempOrder.products, key);
|
|
298
|
+
quantity = Math.max(0, Math.floor(Number(product.quantity) || 0));
|
|
299
|
+
if (!(product.repeat_skip && existing.length)) {
|
|
300
|
+
_context.next = 20;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
if (!(quantity === 0)) {
|
|
304
|
+
_context.next = 11;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
_context.next = 10;
|
|
308
|
+
return order.removeProductsFromOrder(existing.map(lineIdentity), {
|
|
309
|
+
isCurrentOrder: targetIsCurrent
|
|
310
|
+
});
|
|
311
|
+
case 10:
|
|
312
|
+
return _context.abrupt("return", 0);
|
|
313
|
+
case 11:
|
|
314
|
+
if (!(existing.length > 1)) {
|
|
315
|
+
_context.next = 14;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
_context.next = 14;
|
|
319
|
+
return order.removeProductsFromOrder(existing.slice(1).map(lineIdentity), {
|
|
320
|
+
isCurrentOrder: targetIsCurrent
|
|
321
|
+
});
|
|
322
|
+
case 14:
|
|
323
|
+
if (targetIsCurrent()) {
|
|
324
|
+
_context.next = 16;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
return _context.abrupt("return", {
|
|
328
|
+
v: {
|
|
329
|
+
v: void 0
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
case 16:
|
|
333
|
+
if (!(Number(existing[0].num) !== quantity)) {
|
|
334
|
+
_context.next = 19;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
_context.next = 19;
|
|
338
|
+
return order.updateOrderProductQuantity(_objectSpread(_objectSpread({}, lineIdentity(existing[0])), {}, {
|
|
339
|
+
num: quantity
|
|
340
|
+
}), {
|
|
341
|
+
isCurrentOrder: targetIsCurrent
|
|
342
|
+
});
|
|
343
|
+
case 19:
|
|
344
|
+
return _context.abrupt("return", 0);
|
|
345
|
+
case 20:
|
|
346
|
+
if (!(quantity === 0)) {
|
|
347
|
+
_context.next = 22;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
return _context.abrupt("return", 0);
|
|
351
|
+
case 22:
|
|
352
|
+
source = sources.get(Number(product.product_id));
|
|
353
|
+
line = transformBaseProductToOrderProduct({
|
|
354
|
+
sourceProduct: source,
|
|
355
|
+
payload: {
|
|
356
|
+
product_id: product.product_id,
|
|
357
|
+
product_variant_id: (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : 0,
|
|
358
|
+
quantity: quantity
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
if (line) {
|
|
362
|
+
_context.next = 26;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
throw new Error("Unable to prepare fulfillment product ".concat(product.product_id));
|
|
366
|
+
case 26:
|
|
367
|
+
line.metadata = _objectSpread(_objectSpread({}, line.metadata), {}, _defineProperty({}, ownershipField, key));
|
|
368
|
+
beforeProducts = tempOrder.products;
|
|
369
|
+
beforeFingerprint = cartFingerprint(beforeProducts);
|
|
370
|
+
_context.next = 31;
|
|
371
|
+
return order.addProductToOrder(line, undefined, {
|
|
372
|
+
insertAtStart: true,
|
|
373
|
+
disableMerge: true,
|
|
374
|
+
availabilityCommitGuard: function availabilityCommitGuard() {
|
|
375
|
+
if (!targetIsCurrent() || tempOrder.products !== beforeProducts || cartFingerprint(tempOrder.products) !== beforeFingerprint) {
|
|
376
|
+
throw new Error('The order changed while adding a fulfillment product');
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
availabilityCommitTargetGuard: function availabilityCommitTargetGuard() {
|
|
380
|
+
return targetIsCurrent() && ownedLines(tempOrder.products, key).length > 0;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
case 31:
|
|
384
|
+
case "end":
|
|
385
|
+
return _context.stop();
|
|
386
|
+
}
|
|
387
|
+
}, _loop2);
|
|
388
|
+
});
|
|
389
|
+
_iterator3.s();
|
|
390
|
+
case 14:
|
|
391
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
392
|
+
_context2.next = 23;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
return _context2.delegateYield(_loop2(), "t0", 16);
|
|
396
|
+
case 16:
|
|
397
|
+
_ret2 = _context2.t0;
|
|
398
|
+
if (!(_ret2 === 0)) {
|
|
399
|
+
_context2.next = 19;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
return _context2.abrupt("continue", 21);
|
|
403
|
+
case 19:
|
|
404
|
+
if (!_ret2) {
|
|
405
|
+
_context2.next = 21;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
return _context2.abrupt("return", _ret2.v);
|
|
409
|
+
case 21:
|
|
410
|
+
_context2.next = 14;
|
|
411
|
+
break;
|
|
412
|
+
case 23:
|
|
413
|
+
_context2.next = 28;
|
|
414
|
+
break;
|
|
415
|
+
case 25:
|
|
416
|
+
_context2.prev = 25;
|
|
417
|
+
_context2.t1 = _context2["catch"](11);
|
|
418
|
+
_iterator3.e(_context2.t1);
|
|
419
|
+
case 28:
|
|
420
|
+
_context2.prev = 28;
|
|
421
|
+
_iterator3.f();
|
|
422
|
+
return _context2.finish(28);
|
|
423
|
+
case 31:
|
|
424
|
+
case "end":
|
|
425
|
+
return _context2.stop();
|
|
426
|
+
}
|
|
427
|
+
}, _loop, null, [[11, 25, 28, 31]]);
|
|
428
|
+
});
|
|
429
|
+
_iterator2.s();
|
|
430
|
+
case 49:
|
|
431
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
432
|
+
_context3.next = 58;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
return _context3.delegateYield(_loop(), "t8", 51);
|
|
436
|
+
case 51:
|
|
437
|
+
_ret = _context3.t8;
|
|
438
|
+
if (!(_ret === 0)) {
|
|
439
|
+
_context3.next = 54;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
return _context3.abrupt("continue", 56);
|
|
443
|
+
case 54:
|
|
444
|
+
if (!_ret) {
|
|
445
|
+
_context3.next = 56;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
return _context3.abrupt("return", _ret.v);
|
|
449
|
+
case 56:
|
|
450
|
+
_context3.next = 49;
|
|
451
|
+
break;
|
|
452
|
+
case 58:
|
|
453
|
+
_context3.next = 63;
|
|
454
|
+
break;
|
|
455
|
+
case 60:
|
|
456
|
+
_context3.prev = 60;
|
|
457
|
+
_context3.t9 = _context3["catch"](46);
|
|
458
|
+
_iterator2.e(_context3.t9);
|
|
459
|
+
case 63:
|
|
460
|
+
_context3.prev = 63;
|
|
461
|
+
_iterator2.f();
|
|
462
|
+
return _context3.finish(63);
|
|
463
|
+
case 66:
|
|
464
|
+
case "end":
|
|
465
|
+
return _context3.stop();
|
|
466
|
+
}
|
|
467
|
+
}, _callee, null, [[46, 60, 63, 66]]);
|
|
468
|
+
}));
|
|
469
|
+
return function run() {
|
|
470
|
+
return _ref5.apply(this, arguments);
|
|
471
|
+
};
|
|
472
|
+
}();
|
|
473
|
+
// Serialize writes; a newer choice invalidates the old request before its next mutation.
|
|
474
|
+
var task = this.pending.then(run).catch(function (error) {
|
|
475
|
+
if (sequence === _this.sequence) _this.host.reportError(error);
|
|
476
|
+
// Fees are best effort by product decision: Next must remain usable on failure.
|
|
477
|
+
});
|
|
478
|
+
this.pending = task;
|
|
479
|
+
return task;
|
|
480
|
+
}
|
|
481
|
+
}, {
|
|
482
|
+
key: "loadProducts",
|
|
483
|
+
value: function () {
|
|
484
|
+
var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ids) {
|
|
485
|
+
var _this$host$getOrder$g, _this$host$getOrder$g2;
|
|
486
|
+
var products, runtime, now;
|
|
487
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context4) {
|
|
488
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
489
|
+
case 0:
|
|
490
|
+
if (ids.length) {
|
|
491
|
+
_context4.next = 2;
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
return _context4.abrupt("return", []);
|
|
495
|
+
case 2:
|
|
496
|
+
products = this.host.getProducts();
|
|
497
|
+
if (products) {
|
|
498
|
+
_context4.next = 5;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
throw new Error('products module is unavailable for fulfillment item rules');
|
|
502
|
+
case 5:
|
|
503
|
+
runtime = this.host.getOtherParams();
|
|
504
|
+
now = dayjs();
|
|
505
|
+
return _context4.abrupt("return", products.loadProducts({
|
|
506
|
+
product_ids: ids,
|
|
507
|
+
cacheId: runtime.cacheId,
|
|
508
|
+
customer_id: (_this$host$getOrder$g = (_this$host$getOrder$g2 = this.host.getOrder().getTempOrder()) === null || _this$host$getOrder$g2 === void 0 ? void 0 : _this$host$getOrder$g2.customer_id) !== null && _this$host$getOrder$g !== void 0 ? _this$host$getOrder$g : undefined,
|
|
509
|
+
schedule_date: now.format('YYYY-MM-DD'),
|
|
510
|
+
schedule_datetime: now.format('YYYY-MM-DD HH:mm:ss')
|
|
511
|
+
}));
|
|
512
|
+
case 8:
|
|
513
|
+
case "end":
|
|
514
|
+
return _context4.stop();
|
|
515
|
+
}
|
|
516
|
+
}, _callee2, this);
|
|
517
|
+
}));
|
|
518
|
+
function loadProducts(_x) {
|
|
519
|
+
return _loadProducts.apply(this, arguments);
|
|
520
|
+
}
|
|
521
|
+
return loadProducts;
|
|
522
|
+
}()
|
|
523
|
+
}, {
|
|
524
|
+
key: "getMainProductNumber",
|
|
525
|
+
value: function () {
|
|
526
|
+
var _getMainProductNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(lines, configs) {
|
|
527
|
+
var _this$host$getProduct;
|
|
528
|
+
var feeIds, candidates, ids, cached, sources, _iterator4, _step4, _loop3, missing, _iterator5, _step5, _source$id, source;
|
|
529
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context6) {
|
|
530
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
531
|
+
case 0:
|
|
532
|
+
feeIds = new Set(configs.flatMap(function (config) {
|
|
533
|
+
return config.actions.flatMap(function (action) {
|
|
534
|
+
var _action$config2;
|
|
535
|
+
return ((_action$config2 = action.config) === null || _action$config2 === void 0 ? void 0 : _action$config2.scope) === 'set_handover' && ['PREFILL_CART', 'DELETE_PRODUCT'].includes(action.type) ? (action.config.products || []).map(function (product) {
|
|
536
|
+
return Number(product.product_id);
|
|
537
|
+
}) : [];
|
|
538
|
+
});
|
|
539
|
+
}));
|
|
540
|
+
candidates = lines.filter(function (line) {
|
|
541
|
+
var _line$metadata5;
|
|
542
|
+
return !((_line$metadata5 = line.metadata) !== null && _line$metadata5 !== void 0 && _line$metadata5[ownershipField]) && !feeIds.has(Number(line.product_id));
|
|
543
|
+
});
|
|
544
|
+
if (candidates.length) {
|
|
545
|
+
_context6.next = 4;
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
return _context6.abrupt("return", 0);
|
|
549
|
+
case 4:
|
|
550
|
+
ids = positiveIds(candidates.map(function (line) {
|
|
551
|
+
return line.product_id;
|
|
552
|
+
}));
|
|
553
|
+
_context6.next = 7;
|
|
554
|
+
return (_this$host$getProduct = this.host.getProducts()) === null || _this$host$getProduct === void 0 ? void 0 : _this$host$getProduct.queryProducts({
|
|
555
|
+
includeIds: ids
|
|
556
|
+
});
|
|
557
|
+
case 7:
|
|
558
|
+
_context6.t0 = _context6.sent;
|
|
559
|
+
if (_context6.t0) {
|
|
560
|
+
_context6.next = 10;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
_context6.t0 = [];
|
|
564
|
+
case 10:
|
|
565
|
+
cached = _context6.t0;
|
|
566
|
+
sources = new Map();
|
|
567
|
+
_iterator4 = _createForOfIteratorHelper(candidates);
|
|
568
|
+
_context6.prev = 13;
|
|
569
|
+
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
570
|
+
var line, cachedSource, source;
|
|
571
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context5) {
|
|
572
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
573
|
+
case 0:
|
|
574
|
+
line = _step4.value;
|
|
575
|
+
cachedSource = cached.find(function (product) {
|
|
576
|
+
return Number(product.id) === Number(line.product_id);
|
|
577
|
+
});
|
|
578
|
+
source = Array.isArray(cachedSource === null || cachedSource === void 0 ? void 0 : cachedSource.data_variants) ? cachedSource : line._origin;
|
|
579
|
+
if (Array.isArray(source === null || source === void 0 ? void 0 : source.data_variants)) sources.set(Number(line.product_id), source);
|
|
580
|
+
case 4:
|
|
581
|
+
case "end":
|
|
582
|
+
return _context5.stop();
|
|
583
|
+
}
|
|
584
|
+
}, _loop3);
|
|
585
|
+
});
|
|
586
|
+
_iterator4.s();
|
|
587
|
+
case 16:
|
|
588
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
589
|
+
_context6.next = 20;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
return _context6.delegateYield(_loop3(), "t1", 18);
|
|
593
|
+
case 18:
|
|
594
|
+
_context6.next = 16;
|
|
595
|
+
break;
|
|
596
|
+
case 20:
|
|
597
|
+
_context6.next = 25;
|
|
598
|
+
break;
|
|
599
|
+
case 22:
|
|
600
|
+
_context6.prev = 22;
|
|
601
|
+
_context6.t2 = _context6["catch"](13);
|
|
602
|
+
_iterator4.e(_context6.t2);
|
|
603
|
+
case 25:
|
|
604
|
+
_context6.prev = 25;
|
|
605
|
+
_iterator4.f();
|
|
606
|
+
return _context6.finish(25);
|
|
607
|
+
case 28:
|
|
608
|
+
missing = ids.filter(function (id) {
|
|
609
|
+
return !sources.has(id);
|
|
610
|
+
});
|
|
611
|
+
_context6.t3 = _createForOfIteratorHelper;
|
|
612
|
+
_context6.next = 32;
|
|
613
|
+
return this.loadProducts(missing);
|
|
614
|
+
case 32:
|
|
615
|
+
_context6.t4 = _context6.sent;
|
|
616
|
+
_iterator5 = (0, _context6.t3)(_context6.t4);
|
|
617
|
+
try {
|
|
618
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
619
|
+
source = _step5.value;
|
|
620
|
+
sources.set(Number((_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : source.product_id), source);
|
|
621
|
+
}
|
|
622
|
+
} catch (err) {
|
|
623
|
+
_iterator5.e(err);
|
|
624
|
+
} finally {
|
|
625
|
+
_iterator5.f();
|
|
626
|
+
}
|
|
627
|
+
if (!ids.some(function (id) {
|
|
628
|
+
return !sources.has(id);
|
|
629
|
+
})) {
|
|
630
|
+
_context6.next = 37;
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
throw new Error('Unable to identify fulfillment main products');
|
|
634
|
+
case 37:
|
|
635
|
+
return _context6.abrupt("return", candidates.reduce(function (sum, line) {
|
|
636
|
+
var _source$data_variants;
|
|
637
|
+
var source = sources.get(Number(line.product_id));
|
|
638
|
+
var isMain = source === null || source === void 0 || (_source$data_variants = source.data_variants) === null || _source$data_variants === void 0 ? void 0 : _source$data_variants.some(function (variant) {
|
|
639
|
+
var _variant$data;
|
|
640
|
+
return (variant === null || variant === void 0 || (_variant$data = variant.data) === null || _variant$data === void 0 || (_variant$data = _variant$data.client_meta) === null || _variant$data === void 0 ? void 0 : _variant$data.is_main_product) === 1;
|
|
641
|
+
});
|
|
642
|
+
return sum + (isMain ? Math.max(0, Math.floor(Number(line.num) || 0)) : 0);
|
|
643
|
+
}, 0));
|
|
644
|
+
case 38:
|
|
645
|
+
case "end":
|
|
646
|
+
return _context6.stop();
|
|
647
|
+
}
|
|
648
|
+
}, _callee3, this, [[13, 22, 25, 28]]);
|
|
649
|
+
}));
|
|
650
|
+
function getMainProductNumber(_x2, _x3) {
|
|
651
|
+
return _getMainProductNumber.apply(this, arguments);
|
|
652
|
+
}
|
|
653
|
+
return getMainProductNumber;
|
|
654
|
+
}()
|
|
655
|
+
}, {
|
|
656
|
+
key: "loadPrefillSources",
|
|
657
|
+
value: function () {
|
|
658
|
+
var _loadPrefillSources = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(actions, lines) {
|
|
659
|
+
var _this$host$getProduct2;
|
|
660
|
+
var ids, cached, sources, _iterator6, _step6, _line$metadata6, line, _iterator7, _step7, _source$id2, source;
|
|
661
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context7) {
|
|
662
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
663
|
+
case 0:
|
|
664
|
+
ids = positiveIds(actions.flatMap(function (action) {
|
|
665
|
+
return action.type === 'PREFILL_CART' ? action.products.filter(function (product) {
|
|
666
|
+
return product.quantity > 0;
|
|
667
|
+
}).map(function (product) {
|
|
668
|
+
return product.product_id;
|
|
669
|
+
}) : [];
|
|
670
|
+
}));
|
|
671
|
+
if (!ids.length) {
|
|
672
|
+
_context7.next = 10;
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
_context7.next = 4;
|
|
676
|
+
return (_this$host$getProduct2 = this.host.getProducts()) === null || _this$host$getProduct2 === void 0 ? void 0 : _this$host$getProduct2.queryProducts({
|
|
677
|
+
includeIds: ids
|
|
678
|
+
});
|
|
679
|
+
case 4:
|
|
680
|
+
_context7.t1 = _context7.sent;
|
|
681
|
+
if (_context7.t1) {
|
|
682
|
+
_context7.next = 7;
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
_context7.t1 = [];
|
|
686
|
+
case 7:
|
|
687
|
+
_context7.t0 = _context7.t1;
|
|
688
|
+
_context7.next = 11;
|
|
689
|
+
break;
|
|
690
|
+
case 10:
|
|
691
|
+
_context7.t0 = [];
|
|
692
|
+
case 11:
|
|
693
|
+
cached = _context7.t0;
|
|
694
|
+
sources = new Map(cached.map(function (product) {
|
|
695
|
+
return [Number(product.id), product];
|
|
696
|
+
})); // Existing owned rows can supply their original product if the catalog no longer contains it.
|
|
697
|
+
_iterator6 = _createForOfIteratorHelper(lines);
|
|
698
|
+
try {
|
|
699
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
700
|
+
line = _step6.value;
|
|
701
|
+
if ((_line$metadata6 = line.metadata) !== null && _line$metadata6 !== void 0 && _line$metadata6[ownershipField] && line._origin && !sources.has(Number(line.product_id))) {
|
|
702
|
+
sources.set(Number(line.product_id), line._origin);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
} catch (err) {
|
|
706
|
+
_iterator6.e(err);
|
|
707
|
+
} finally {
|
|
708
|
+
_iterator6.f();
|
|
709
|
+
}
|
|
710
|
+
_context7.t2 = _createForOfIteratorHelper;
|
|
711
|
+
_context7.next = 18;
|
|
712
|
+
return this.loadProducts(ids.filter(function (id) {
|
|
713
|
+
return !sources.has(id);
|
|
714
|
+
}));
|
|
715
|
+
case 18:
|
|
716
|
+
_context7.t3 = _context7.sent;
|
|
717
|
+
_iterator7 = (0, _context7.t2)(_context7.t3);
|
|
718
|
+
try {
|
|
719
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
720
|
+
source = _step7.value;
|
|
721
|
+
sources.set(Number((_source$id2 = source.id) !== null && _source$id2 !== void 0 ? _source$id2 : source.product_id), source);
|
|
722
|
+
}
|
|
723
|
+
} catch (err) {
|
|
724
|
+
_iterator7.e(err);
|
|
725
|
+
} finally {
|
|
726
|
+
_iterator7.f();
|
|
727
|
+
}
|
|
728
|
+
if (!ids.some(function (id) {
|
|
729
|
+
return !sources.has(id);
|
|
730
|
+
})) {
|
|
731
|
+
_context7.next = 23;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
throw new Error('Unable to load fulfillment fee products');
|
|
735
|
+
case 23:
|
|
736
|
+
return _context7.abrupt("return", sources);
|
|
737
|
+
case 24:
|
|
738
|
+
case "end":
|
|
739
|
+
return _context7.stop();
|
|
740
|
+
}
|
|
741
|
+
}, _callee4, this);
|
|
742
|
+
}));
|
|
743
|
+
function loadPrefillSources(_x4, _x5) {
|
|
744
|
+
return _loadPrefillSources.apply(this, arguments);
|
|
745
|
+
}
|
|
746
|
+
return loadPrefillSources;
|
|
747
|
+
}()
|
|
748
|
+
}]);
|
|
749
|
+
return FulfillmentItemRulesController;
|
|
750
|
+
}();
|