@feedmepos/order-plugin-gallery 0.0.10-beta.3 → 0.0.10-beta.5

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.
@@ -92,19 +92,23 @@ const autoAddCompulsoryItems = async (sdk, rules, slotActiveBills) => {
92
92
  await sdk.orderManager.updateItems(itemsToAdd);
93
93
  }
94
94
  };
95
- const compulsoryItemsPlugin = ({ sdk, onOrderSessionReady, onBeforeSubmitOrder, pluginParams, }) => {
95
+ const compulsoryItemsPlugin = (args) => {
96
+ const { sdk, onBeforeSubmitOrder, pluginParams } = args;
97
+ const { onOrderSessionReady } = args;
96
98
  const getRules = () => {
97
99
  const params = (pluginParams || {});
98
100
  return getNormalizedRules(params.itemLimitConfig);
99
101
  };
100
- onOrderSessionReady(async (params) => {
101
- if (params.isPreviewMode)
102
- return;
103
- const rules = getRules();
104
- if (rules.length === 0)
105
- return;
106
- await autoAddCompulsoryItems(sdk, rules, params.slotActiveBills);
107
- });
102
+ if (typeof onOrderSessionReady === "function") {
103
+ onOrderSessionReady(async (params) => {
104
+ if (params.isPreviewMode)
105
+ return;
106
+ const rules = getRules();
107
+ if (rules.length === 0)
108
+ return;
109
+ await autoAddCompulsoryItems(sdk, rules, params.slotActiveBills);
110
+ });
111
+ }
108
112
  onBeforeSubmitOrder(() => {
109
113
  const rules = getRules();
110
114
  if (rules.length === 0)
@@ -1,7 +1,8 @@
1
1
  const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitOrder, pluginParams, }) => {
2
- const MIN_ITEMS = 1;
3
- const MAX_ITEMS = 1;
4
2
  const categoryLimitConfig = pluginParams?.categoryLimitConfig || {};
3
+ const minItems = categoryLimitConfig.minItems ?? 1;
4
+ const maxItems = categoryLimitConfig.maxItems ?? 1;
5
+ const formatCountLabel = (count) => `${count} ${count === 1 ? "item" : "items"}`;
5
6
  onBeforeSubmitOrder(() => {
6
7
  if (!categoryLimitConfig.categoryId) {
7
8
  return true;
@@ -58,14 +59,12 @@ const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitO
58
59
  return true;
59
60
  }
60
61
  const totalItems = numberOfTotalItems.submitted + numberOfTotalItems.inCart;
61
- if (totalItems > MAX_ITEMS) {
62
- const extraItems = totalItems - MAX_ITEMS;
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.`);
62
+ if (totalItems > maxItems) {
63
+ toast(`You can only choose up to ${formatCountLabel(maxItems)} of ${targetCategory.name}. Please remove extra ${targetCategory.name} from cart to continue.`);
65
64
  return false;
66
65
  }
67
- if (totalItems < MIN_ITEMS) {
68
- toast(`Please add one ${targetCategory.name} to cart to continue.`);
66
+ if (totalItems < minItems) {
67
+ toast(`Please add at least ${formatCountLabel(minItems)} of ${targetCategory.name} to cart to continue.`);
69
68
  return false;
70
69
  }
71
70
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedmepos/order-plugin-gallery",
3
- "version": "0.0.10-beta.3",
3
+ "version": "0.0.10-beta.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"