@feedmepos/order-plugin-gallery 0.0.5 → 0.0.7
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitOrder, pluginParams, }) => {
|
|
2
|
-
const MAX_FREE_ITEMS = 1;
|
|
3
2
|
const MIN_ITEMS = 1;
|
|
4
|
-
const MAX_ITEMS =
|
|
3
|
+
const MAX_ITEMS = 1;
|
|
5
4
|
const categoryLimitConfig = pluginParams?.categoryLimitConfig || {};
|
|
6
5
|
onBeforeSubmitOrder(() => {
|
|
7
6
|
if (!categoryLimitConfig.categoryId) {
|
|
@@ -43,47 +42,30 @@ const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitO
|
|
|
43
42
|
return { menuItem, quantity: item.quantity };
|
|
44
43
|
})
|
|
45
44
|
.filter((entry) => Boolean(entry));
|
|
46
|
-
// const numberOfFreeItems = {
|
|
47
|
-
// submitted: submittedItemsInCategory.reduce((sum, entry) => {
|
|
48
|
-
// return entry.menuItem.price.amount === 0 ? sum + entry.quantity : sum;
|
|
49
|
-
// }, 0),
|
|
50
|
-
// inCart: cartItemsInCategory.reduce((sum, entry) => {
|
|
51
|
-
// return entry.menuItem.price.amount === 0 ? sum + entry.quantity : sum;
|
|
52
|
-
// }, 0),
|
|
53
|
-
// };
|
|
54
45
|
const numberOfTotalItems = {
|
|
55
46
|
submitted: submittedItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
|
|
56
47
|
inCart: cartItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
|
|
57
48
|
};
|
|
58
49
|
const toast = (message) => {
|
|
59
50
|
sdk.ui.toast.show({
|
|
60
|
-
title:
|
|
51
|
+
title: message,
|
|
61
52
|
type: "error",
|
|
62
53
|
duration: 5000,
|
|
63
54
|
});
|
|
64
55
|
};
|
|
65
56
|
// POS already ordered, and customer have not added more target items to cart, we ignore the validation
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// const totalFreeItems =
|
|
70
|
-
// numberOfFreeItems.submitted + numberOfFreeItems.inCart;
|
|
57
|
+
if (numberOfTotalItems.submitted > 0 && numberOfTotalItems.inCart === 0) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
71
60
|
const totalItems = numberOfTotalItems.submitted + numberOfTotalItems.inCart;
|
|
72
|
-
// if (totalFreeItems > MAX_FREE_ITEMS) {
|
|
73
|
-
// const overFreeItems = totalFreeItems - MAX_FREE_ITEMS;
|
|
74
|
-
// toast(
|
|
75
|
-
// `Remove ${overFreeItems} free ${targetCategory.name} from cart to continue. `
|
|
76
|
-
// );
|
|
77
|
-
// return false;
|
|
78
|
-
// }
|
|
79
61
|
if (totalItems > MAX_ITEMS) {
|
|
80
62
|
const extraItems = totalItems - MAX_ITEMS;
|
|
81
|
-
|
|
63
|
+
const extraLabel = extraItems === 1 ? "item" : "items";
|
|
64
|
+
toast(`You can only choose one ${targetCategory.name}. Please remove extra ${targetCategory.name} from cart to continue.`);
|
|
82
65
|
return false;
|
|
83
66
|
}
|
|
84
67
|
if (totalItems < MIN_ITEMS) {
|
|
85
|
-
|
|
86
|
-
toast(`Add at least ${remainingItems} more ${targetCategory.name} to cart to continue. `);
|
|
68
|
+
toast(`Please add one ${targetCategory.name} to cart to continue.`);
|
|
87
69
|
return false;
|
|
88
70
|
}
|
|
89
71
|
return true;
|