@open-tender/utils 0.5.46 → 0.5.48
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/utils/cart.js +16 -2
- package/dist/esm/utils/cart.js +16 -2
- package/package.json +1 -1
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -726,6 +726,18 @@ const makeGroupsLookup = (item) => {
|
|
|
726
726
|
return grpObj;
|
|
727
727
|
}, {});
|
|
728
728
|
};
|
|
729
|
+
const makeGroupsLookupByExtId = (item) => {
|
|
730
|
+
return item.groups.reduce((grpObj, i) => {
|
|
731
|
+
const options = i.options.reduce((optObj, o) => {
|
|
732
|
+
if (o.pos_ext_id) {
|
|
733
|
+
optObj[o.pos_ext_id] = o;
|
|
734
|
+
}
|
|
735
|
+
return optObj;
|
|
736
|
+
}, {});
|
|
737
|
+
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
738
|
+
return grpObj;
|
|
739
|
+
}, {});
|
|
740
|
+
};
|
|
729
741
|
// TODO: refactor for nested modifiers
|
|
730
742
|
const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
731
743
|
const itemIds = cart.map(item => item.id);
|
|
@@ -746,6 +758,7 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
746
758
|
const missingOptions = [];
|
|
747
759
|
const invalidOptions = [];
|
|
748
760
|
const newGroups = makeGroupsLookup(newItem);
|
|
761
|
+
const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
|
|
749
762
|
// check if any required groups for the new item are missing from the old item
|
|
750
763
|
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
751
764
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
@@ -757,7 +770,7 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
757
770
|
.map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
|
|
758
771
|
const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
|
|
759
772
|
const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
|
|
760
|
-
const newGroup = newGroups[group.id];
|
|
773
|
+
const newGroup = newGroups[group.id] || newGroupsByExtId[group.id];
|
|
761
774
|
// check if option group is still part of the item
|
|
762
775
|
if (!newGroup) {
|
|
763
776
|
if (optionCount > 0) {
|
|
@@ -770,7 +783,8 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
770
783
|
}
|
|
771
784
|
else {
|
|
772
785
|
const updatedOptions = group.options.map(option => {
|
|
773
|
-
const newOption = newGroup.options[option.id]
|
|
786
|
+
const newOption = newGroup.options[option.id] ||
|
|
787
|
+
(option.pos_ext_id && newGroup.options[option.pos_ext_id]);
|
|
774
788
|
// check to see if any OLD options aren't avaiilable on the current menu
|
|
775
789
|
// or if any of the options are currently sold out
|
|
776
790
|
if (!newOption ||
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -690,6 +690,18 @@ const makeGroupsLookup = (item) => {
|
|
|
690
690
|
return grpObj;
|
|
691
691
|
}, {});
|
|
692
692
|
};
|
|
693
|
+
const makeGroupsLookupByExtId = (item) => {
|
|
694
|
+
return item.groups.reduce((grpObj, i) => {
|
|
695
|
+
const options = i.options.reduce((optObj, o) => {
|
|
696
|
+
if (o.pos_ext_id) {
|
|
697
|
+
optObj[o.pos_ext_id] = o;
|
|
698
|
+
}
|
|
699
|
+
return optObj;
|
|
700
|
+
}, {});
|
|
701
|
+
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
702
|
+
return grpObj;
|
|
703
|
+
}, {});
|
|
704
|
+
};
|
|
693
705
|
// TODO: refactor for nested modifiers
|
|
694
706
|
export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
695
707
|
const itemIds = cart.map(item => item.id);
|
|
@@ -710,6 +722,7 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
710
722
|
const missingOptions = [];
|
|
711
723
|
const invalidOptions = [];
|
|
712
724
|
const newGroups = makeGroupsLookup(newItem);
|
|
725
|
+
const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
|
|
713
726
|
// check if any required groups for the new item are missing from the old item
|
|
714
727
|
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
715
728
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
@@ -721,7 +734,7 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
721
734
|
.map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
|
|
722
735
|
const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
|
|
723
736
|
const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
|
|
724
|
-
const newGroup = newGroups[group.id];
|
|
737
|
+
const newGroup = newGroups[group.id] || newGroupsByExtId[group.id];
|
|
725
738
|
// check if option group is still part of the item
|
|
726
739
|
if (!newGroup) {
|
|
727
740
|
if (optionCount > 0) {
|
|
@@ -734,7 +747,8 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
734
747
|
}
|
|
735
748
|
else {
|
|
736
749
|
const updatedOptions = group.options.map(option => {
|
|
737
|
-
const newOption = newGroup.options[option.id]
|
|
750
|
+
const newOption = newGroup.options[option.id] ||
|
|
751
|
+
(option.pos_ext_id && newGroup.options[option.pos_ext_id]);
|
|
738
752
|
// check to see if any OLD options aren't avaiilable on the current menu
|
|
739
753
|
// or if any of the options are currently sold out
|
|
740
754
|
if (!newOption ||
|
package/package.json
CHANGED