@feedmepos/order-plugin-gallery 0.0.4 → 0.0.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.
@@ -1,6 +1,7 @@
1
1
  const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitOrder, pluginParams, }) => {
2
2
  const MAX_FREE_ITEMS = 1;
3
- const TOTAL_ITEMS = 2;
3
+ const MIN_ITEMS = 1;
4
+ const MAX_ITEMS = 2;
4
5
  const categoryLimitConfig = pluginParams?.categoryLimitConfig || {};
5
6
  onBeforeSubmitOrder(() => {
6
7
  if (!categoryLimitConfig.categoryId) {
@@ -42,44 +43,47 @@ const maxItemInCategoryPlugin = ({ sdk, onAfterComputeMenuState, onBeforeSubmitO
42
43
  return { menuItem, quantity: item.quantity };
43
44
  })
44
45
  .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
- };
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
+ // };
53
54
  const numberOfTotalItems = {
54
55
  submitted: submittedItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
55
56
  inCart: cartItemsInCategory.reduce((sum, entry) => sum + entry.quantity, 0),
56
57
  };
57
58
  const toast = (message) => {
58
59
  sdk.ui.toast.show({
59
- title: `Please order ${TOTAL_ITEMS} products with up to ${MAX_FREE_ITEMS} free product from "${targetCategory.name}". ${message}`,
60
+ title: `Please order one or two "${targetCategory.name}". ${message}`,
60
61
  type: "error",
61
62
  duration: 5000,
62
63
  });
63
64
  };
64
65
  // POS already ordered, and customer have not added more target items to cart, we ignore the validation
65
- if (numberOfTotalItems.submitted > 0 && numberOfTotalItems.inCart === 0) {
66
- return true;
67
- }
68
- const totalFreeItems = numberOfFreeItems.submitted + numberOfFreeItems.inCart;
66
+ // if (numberOfTotalItems.submitted > 0 && numberOfTotalItems.inCart === 0) {
67
+ // return true;
68
+ // }
69
+ // const totalFreeItems =
70
+ // numberOfFreeItems.submitted + numberOfFreeItems.inCart;
69
71
  const totalItems = numberOfTotalItems.submitted + numberOfTotalItems.inCart;
70
- if (totalFreeItems > MAX_FREE_ITEMS) {
71
- const overFreeItems = totalFreeItems - MAX_FREE_ITEMS;
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;
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
+ if (totalItems > MAX_ITEMS) {
80
+ const extraItems = totalItems - MAX_ITEMS;
77
81
  toast(`Remove ${extraItems} ${targetCategory.name} from cart to continue. `);
78
82
  return false;
79
83
  }
80
- if (totalItems < TOTAL_ITEMS) {
81
- const remainingItems = TOTAL_ITEMS - totalItems;
82
- toast(`Add ${remainingItems} more ${targetCategory.name} to cart to continue. `);
84
+ if (totalItems < MIN_ITEMS) {
85
+ const remainingItems = MIN_ITEMS - totalItems;
86
+ toast(`Add at least ${remainingItems} more ${targetCategory.name} to cart to continue. `);
83
87
  return false;
84
88
  }
85
89
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedmepos/order-plugin-gallery",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"