@open-tender/utils 0.5.49 → 0.5.51
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 +9 -16
- package/dist/esm/utils/cart.js +9 -16
- package/package.json +1 -1
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -726,18 +726,6 @@ 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
|
-
};
|
|
741
729
|
// TODO: refactor for nested modifiers
|
|
742
730
|
const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
743
731
|
const itemIds = cart.map(item => item.id);
|
|
@@ -758,7 +746,6 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
758
746
|
const missingOptions = [];
|
|
759
747
|
const invalidOptions = [];
|
|
760
748
|
const newGroups = makeGroupsLookup(newItem);
|
|
761
|
-
const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
|
|
762
749
|
// check if any required groups for the new item are missing from the old item
|
|
763
750
|
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
764
751
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
@@ -771,7 +758,6 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
771
758
|
const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
|
|
772
759
|
const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
|
|
773
760
|
const newGroup = newGroups[group.id];
|
|
774
|
-
const newGroupByExtId = newGroupsByExtId[group.id];
|
|
775
761
|
// check if option group is still part of the item
|
|
776
762
|
if (!newGroup) {
|
|
777
763
|
if (optionCount > 0) {
|
|
@@ -784,8 +770,15 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
784
770
|
}
|
|
785
771
|
else {
|
|
786
772
|
const updatedOptions = group.options.map(option => {
|
|
787
|
-
|
|
788
|
-
|
|
773
|
+
let newOption = newGroup.options[option.id];
|
|
774
|
+
if (!newOption) {
|
|
775
|
+
console.log('checking pos_ext_id for option match');
|
|
776
|
+
const allOptions = Object.values(newGroup.options);
|
|
777
|
+
const matchingOption = allOptions.find(o => o.pos_ext_id === option.pos_ext_id);
|
|
778
|
+
console.log(allOptions, option, matchingOption);
|
|
779
|
+
if (matchingOption)
|
|
780
|
+
newOption = matchingOption;
|
|
781
|
+
}
|
|
789
782
|
// check to see if any OLD options aren't avaiilable on the current menu
|
|
790
783
|
// or if any of the options are currently sold out
|
|
791
784
|
if (!newOption ||
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -690,18 +690,6 @@ 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
|
-
};
|
|
705
693
|
// TODO: refactor for nested modifiers
|
|
706
694
|
export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
707
695
|
const itemIds = cart.map(item => item.id);
|
|
@@ -722,7 +710,6 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
722
710
|
const missingOptions = [];
|
|
723
711
|
const invalidOptions = [];
|
|
724
712
|
const newGroups = makeGroupsLookup(newItem);
|
|
725
|
-
const newGroupsByExtId = makeGroupsLookupByExtId(newItem);
|
|
726
713
|
// check if any required groups for the new item are missing from the old item
|
|
727
714
|
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
728
715
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
@@ -735,7 +722,6 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
735
722
|
const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
|
|
736
723
|
const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
|
|
737
724
|
const newGroup = newGroups[group.id];
|
|
738
|
-
const newGroupByExtId = newGroupsByExtId[group.id];
|
|
739
725
|
// check if option group is still part of the item
|
|
740
726
|
if (!newGroup) {
|
|
741
727
|
if (optionCount > 0) {
|
|
@@ -748,8 +734,15 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
|
|
|
748
734
|
}
|
|
749
735
|
else {
|
|
750
736
|
const updatedOptions = group.options.map(option => {
|
|
751
|
-
|
|
752
|
-
|
|
737
|
+
let newOption = newGroup.options[option.id];
|
|
738
|
+
if (!newOption) {
|
|
739
|
+
console.log('checking pos_ext_id for option match');
|
|
740
|
+
const allOptions = Object.values(newGroup.options);
|
|
741
|
+
const matchingOption = allOptions.find(o => o.pos_ext_id === option.pos_ext_id);
|
|
742
|
+
console.log(allOptions, option, matchingOption);
|
|
743
|
+
if (matchingOption)
|
|
744
|
+
newOption = matchingOption;
|
|
745
|
+
}
|
|
753
746
|
// check to see if any OLD options aren't avaiilable on the current menu
|
|
754
747
|
// or if any of the options are currently sold out
|
|
755
748
|
if (!newOption ||
|
package/package.json
CHANGED