@feedmepos/order-plugin-gallery 0.0.4 → 0.0.6
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,6 +1,6 @@
|
|
|
1
1
|
const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitOrder, pluginParams, }) => {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const MIN_ITEMS = 1;
|
|
3
|
+
const MAX_ITEMS = 2;
|
|
4
4
|
const categoryLimitConfig = pluginParams?.categoryLimitConfig || {};
|
|
5
5
|
onBeforeSubmitOrder(() => {
|
|
6
6
|
if (!categoryLimitConfig.categoryId) {
|
|
@@ -42,21 +42,13 @@ const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitO
|
|
|
42
42
|
return { menuItem, quantity: item.quantity };
|
|
43
43
|
})
|
|
44
44
|
.filter((entry) => Boolean(entry));
|
|
45
|
-
const numberOfFreeItems = {
|
|
46
|
-
submitted: submittedItemsInCategory.reduce((sum, entry) => {
|
|
47
|
-
return entry.menuItem.price.amount === 0 ? sum + entry.quantity : sum;
|
|
48
|
-
}, 0),
|
|
49
|
-
inCart: cartItemsInCategory.reduce((sum, entry) => {
|
|
50
|
-
return entry.menuItem.price.amount === 0 ? sum + entry.quantity : sum;
|
|
51
|
-
}, 0),
|
|
52
|
-
};
|
|
53
45
|
const numberOfTotalItems = {
|
|
54
46
|
submitted: submittedItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
|
|
55
47
|
inCart: cartItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
|
|
56
48
|
};
|
|
57
49
|
const toast = (message) => {
|
|
58
50
|
sdk.ui.toast.show({
|
|
59
|
-
title: `Please order
|
|
51
|
+
title: `Please order one or two "${targetCategory.name}". ${message}`,
|
|
60
52
|
type: "error",
|
|
61
53
|
duration: 5000,
|
|
62
54
|
});
|
|
@@ -65,21 +57,15 @@ const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitO
|
|
|
65
57
|
if (numberOfTotalItems.submitted > 0 && numberOfTotalItems.inCart === 0) {
|
|
66
58
|
return true;
|
|
67
59
|
}
|
|
68
|
-
const totalFreeItems = numberOfFreeItems.submitted + numberOfFreeItems.inCart;
|
|
69
60
|
const totalItems = numberOfTotalItems.submitted + numberOfTotalItems.inCart;
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
toast(`Remove ${overFreeItems} free ${targetCategory.name} from cart to continue. `);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (totalItems > TOTAL_ITEMS) {
|
|
76
|
-
const extraItems = totalItems - TOTAL_ITEMS;
|
|
61
|
+
if (totalItems > MAX_ITEMS) {
|
|
62
|
+
const extraItems = totalItems - MAX_ITEMS;
|
|
77
63
|
toast(`Remove ${extraItems} ${targetCategory.name} from cart to continue. `);
|
|
78
64
|
return false;
|
|
79
65
|
}
|
|
80
|
-
if (totalItems <
|
|
81
|
-
const remainingItems =
|
|
82
|
-
toast(`Add ${remainingItems} more ${targetCategory.name} to cart to continue. `);
|
|
66
|
+
if (totalItems < MIN_ITEMS) {
|
|
67
|
+
const remainingItems = MIN_ITEMS - totalItems;
|
|
68
|
+
toast(`Add at least ${remainingItems} more ${targetCategory.name} to cart to continue. `);
|
|
83
69
|
return false;
|
|
84
70
|
}
|
|
85
71
|
return true;
|