ordering-components-external 13.2.24 → 13.2.25

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.
Files changed (14) hide show
  1. package/_bundles/{7.ordering-component.0599c79450fa3a01dd9f.js → 7.ordering-component.4a1e766eb57cfebad17d.js} +1 -1
  2. package/_bundles/{ordering-component.0599c79450fa3a01dd9f.js → ordering-component.4a1e766eb57cfebad17d.js} +2 -2
  3. package/_modules/components/ProductOptionSuboption/index.js +37 -4
  4. package/package.json +1 -1
  5. package/src/components/ProductOptionSuboption/index.js +48 -4
  6. /package/_bundles/{0.ordering-component.0599c79450fa3a01dd9f.js → 0.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  7. /package/_bundles/{1.ordering-component.0599c79450fa3a01dd9f.js → 1.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  8. /package/_bundles/{2.ordering-component.0599c79450fa3a01dd9f.js → 2.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  9. /package/_bundles/{4.ordering-component.0599c79450fa3a01dd9f.js → 4.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  10. /package/_bundles/{5.ordering-component.0599c79450fa3a01dd9f.js → 5.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  11. /package/_bundles/{6.ordering-component.0599c79450fa3a01dd9f.js → 6.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  12. /package/_bundles/{7.ordering-component.0599c79450fa3a01dd9f.js.LICENSE.txt → 7.ordering-component.4a1e766eb57cfebad17d.js.LICENSE.txt} +0 -0
  13. /package/_bundles/{8.ordering-component.0599c79450fa3a01dd9f.js → 8.ordering-component.4a1e766eb57cfebad17d.js} +0 -0
  14. /package/_bundles/{ordering-component.0599c79450fa3a01dd9f.js.LICENSE.txt → ordering-component.4a1e766eb57cfebad17d.js.LICENSE.txt} +0 -0
@@ -73,13 +73,16 @@ var ProductOptionSuboption = exports.ProductOptionSuboption = function ProductOp
73
73
  var selectStatus = isOrigin ? !state.selected : state.selected;
74
74
  var minMaxValidation = option.with_half_option ? usePizzaValidation : balance === option.max && !((option === null || option === void 0 ? void 0 : option.max) === 1 && (option === null || option === void 0 ? void 0 : option.min) === 1);
75
75
  var canBeSelectedByHalf = (pizzaState === null || pizzaState === void 0 || (_pizzaState2 = pizzaState["option:".concat(option === null || option === void 0 ? void 0 : option.id)]) === null || _pizzaState2 === void 0 ? void 0 : _pizzaState2.value) === option.max - 0.5 && option.with_half_option;
76
+ var shouldApplyHalfLogic = (option === null || option === void 0 ? void 0 : option.with_half_option) && (option === null || option === void 0 ? void 0 : option.allow_suboption_quantity) && (option === null || option === void 0 ? void 0 : option.limit_suboptions_by_max);
77
+ var remainingBalance = option.max - balance;
78
+ var canOnlySelectHalf = shouldApplyHalfLogic && remainingBalance < 1 && remainingBalance > 0;
76
79
  if (selectStatus && (option.limit_suboptions_by_max || isAlsea) && minMaxValidation && !canBeSelectedByHalf) {
77
80
  return;
78
81
  }
79
82
  changeState(_objectSpread(_objectSpread({}, state), {}, {
80
83
  quantity: state.selected ? 0 : 1,
81
84
  selected: !state.selected,
82
- position: canBeSelectedByHalf ? 'left' : 'whole'
85
+ position: canBeSelectedByHalf || canOnlySelectHalf ? 'left' : 'whole'
83
86
  }));
84
87
  };
85
88
 
@@ -87,12 +90,27 @@ var ProductOptionSuboption = exports.ProductOptionSuboption = function ProductOp
87
90
  * Increment suboption quantity
88
91
  */
89
92
  var increment = function increment() {
93
+ var shouldApplyHalfLogic = (option === null || option === void 0 ? void 0 : option.with_half_option) && (option === null || option === void 0 ? void 0 : option.allow_suboption_quantity) && (option === null || option === void 0 ? void 0 : option.limit_suboptions_by_max);
94
+ var maxByPosition = shouldApplyHalfLogic && state.position !== 'whole' ? suboption.max * 2 : suboption.max;
95
+
96
+ // Validar si incrementar excedería el máximo de la opción cuando está en 'whole'
97
+ if (shouldApplyHalfLogic && state.position === 'whole') {
98
+ var _pizzaState3;
99
+ var otherOptionsValue = pizzaState === null || pizzaState === void 0 || (_pizzaState3 = pizzaState["option:".concat(option === null || option === void 0 ? void 0 : option.id)]) === null || _pizzaState3 === void 0 ? void 0 : _pizzaState3.value;
100
+ var wouldExceedMax = otherOptionsValue + 1 > option.max;
101
+ if (wouldExceedMax) {
102
+ return;
103
+ }
104
+ }
90
105
  if (!(option !== null && option !== void 0 && option.with_half_option) && option.limit_suboptions_by_max && (balance === option.max || state.quantity === suboption.max)) {
91
106
  return;
92
107
  }
93
108
  if (!(option !== null && option !== void 0 && option.with_half_option) && !option.limit_suboptions_by_max && state.quantity === suboption.max) {
94
109
  return;
95
110
  }
111
+ if (shouldApplyHalfLogic && state.quantity === maxByPosition) {
112
+ return;
113
+ }
96
114
  if (option !== null && option !== void 0 && option.with_half_option && usePizzaValidation) {
97
115
  return;
98
116
  }
@@ -123,16 +141,31 @@ var ProductOptionSuboption = exports.ProductOptionSuboption = function ProductOp
123
141
  */
124
142
  var changePosition = function changePosition(position) {
125
143
  var price = option.with_half_option && suboption.half_price && position !== 'whole' ? suboption.half_price : suboption.price;
144
+ var shouldApplyHalfLogic = (option === null || option === void 0 ? void 0 : option.with_half_option) && (option === null || option === void 0 ? void 0 : option.allow_suboption_quantity) && (option === null || option === void 0 ? void 0 : option.limit_suboptions_by_max);
145
+ if (shouldApplyHalfLogic && position === 'whole') {
146
+ var _pizzaState4;
147
+ var otherOptionsValue = pizzaState === null || pizzaState === void 0 || (_pizzaState4 = pizzaState["option:".concat(option === null || option === void 0 ? void 0 : option.id)]) === null || _pizzaState4 === void 0 ? void 0 : _pizzaState4.value;
148
+ var additionalValue = position === 'whole' ? state.quantity / 2 : 0;
149
+ var wouldExceedMax = otherOptionsValue + additionalValue > option.max;
150
+ if (wouldExceedMax) {
151
+ return;
152
+ }
153
+ }
154
+ var newQuantity = state.quantity;
155
+ if (shouldApplyHalfLogic && position === 'whole' && state.quantity > suboption.max) {
156
+ newQuantity = suboption.max;
157
+ }
126
158
  changeState(_objectSpread(_objectSpread({}, state), {}, {
127
159
  position: position,
128
160
  price: price,
129
- total: price * state.quantity
161
+ quantity: newQuantity,
162
+ total: price * newQuantity
130
163
  }));
131
164
  };
132
165
 
133
166
  /**
134
- * Change position of the suboption
135
- * @param {string} position Position of the suboption
167
+ * Change quantity of the suboption
168
+ * @param {number} quantity Quantity of the suboption
136
169
  */
137
170
  var changeQuantity = function changeQuantity(quantity) {
138
171
  changeState(_objectSpread(_objectSpread({}, state), {}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-components-external",
3
- "version": "13.2.24",
3
+ "version": "13.2.25",
4
4
  "description": "Ordering Internal Dashboard",
5
5
  "main": "./_modules/index.js",
6
6
  "scripts": {
@@ -51,14 +51,20 @@ export const ProductOptionSuboption = (props) => {
51
51
  const selectStatus = isOrigin ? !state.selected : state.selected
52
52
  const minMaxValidation = option.with_half_option ? usePizzaValidation : (balance === option.max && !(option?.max === 1 && option?.min === 1))
53
53
  const canBeSelectedByHalf = (pizzaState?.[`option:${option?.id}`]?.value === (option.max - 0.5)) && option.with_half_option
54
+
55
+ const shouldApplyHalfLogic = option?.with_half_option && option?.allow_suboption_quantity && option?.limit_suboptions_by_max
56
+ const remainingBalance = option.max - balance
57
+ const canOnlySelectHalf = shouldApplyHalfLogic && remainingBalance < 1 && remainingBalance > 0
58
+
54
59
  if (selectStatus && (option.limit_suboptions_by_max || isAlsea) && minMaxValidation && !canBeSelectedByHalf) {
55
60
  return
56
61
  }
62
+
57
63
  changeState({
58
64
  ...state,
59
65
  quantity: state.selected ? 0 : 1,
60
66
  selected: !state.selected,
61
- position: canBeSelectedByHalf ? 'left' : 'whole'
67
+ position: (canBeSelectedByHalf || canOnlySelectHalf) ? 'left' : 'whole'
62
68
  })
63
69
  }
64
70
 
@@ -66,15 +72,34 @@ export const ProductOptionSuboption = (props) => {
66
72
  * Increment suboption quantity
67
73
  */
68
74
  const increment = () => {
75
+ const shouldApplyHalfLogic = option?.with_half_option && option?.allow_suboption_quantity && option?.limit_suboptions_by_max
76
+ const maxByPosition = shouldApplyHalfLogic && state.position !== 'whole'
77
+ ? suboption.max * 2
78
+ : suboption.max
79
+
80
+ // Validar si incrementar excedería el máximo de la opción cuando está en 'whole'
81
+ if (shouldApplyHalfLogic && state.position === 'whole') {
82
+ const otherOptionsValue = pizzaState?.[`option:${option?.id}`]?.value
83
+ const wouldExceedMax = (otherOptionsValue + 1) > option.max
84
+
85
+ if (wouldExceedMax) {
86
+ return
87
+ }
88
+ }
89
+
69
90
  if (!option?.with_half_option && option.limit_suboptions_by_max && (balance === option.max || state.quantity === suboption.max)) {
70
91
  return
71
92
  }
72
93
  if (!option?.with_half_option && !option.limit_suboptions_by_max && state.quantity === suboption.max) {
73
94
  return
74
95
  }
96
+ if (shouldApplyHalfLogic && state.quantity === maxByPosition) {
97
+ return
98
+ }
75
99
  if (option?.with_half_option && usePizzaValidation) {
76
100
  return
77
101
  }
102
+
78
103
  changeState({
79
104
  ...state,
80
105
  selected: state.quantity === 0 ? true : state.selected,
@@ -104,17 +129,36 @@ export const ProductOptionSuboption = (props) => {
104
129
  */
105
130
  const changePosition = (position) => {
106
131
  const price = option.with_half_option && suboption.half_price && position !== 'whole' ? suboption.half_price : suboption.price
132
+
133
+ const shouldApplyHalfLogic = option?.with_half_option && option?.allow_suboption_quantity && option?.limit_suboptions_by_max
134
+
135
+ if (shouldApplyHalfLogic && position === 'whole') {
136
+ const otherOptionsValue = pizzaState?.[`option:${option?.id}`]?.value
137
+ const additionalValue = position === 'whole' ? state.quantity / 2 : 0
138
+ const wouldExceedMax = (otherOptionsValue + additionalValue) > option.max
139
+
140
+ if (wouldExceedMax) {
141
+ return
142
+ }
143
+ }
144
+
145
+ let newQuantity = state.quantity
146
+ if (shouldApplyHalfLogic && position === 'whole' && state.quantity > suboption.max) {
147
+ newQuantity = suboption.max
148
+ }
149
+
107
150
  changeState({
108
151
  ...state,
109
152
  position,
110
153
  price,
111
- total: price * state.quantity
154
+ quantity: newQuantity,
155
+ total: price * newQuantity
112
156
  })
113
157
  }
114
158
 
115
159
  /**
116
- * Change position of the suboption
117
- * @param {string} position Position of the suboption
160
+ * Change quantity of the suboption
161
+ * @param {number} quantity Quantity of the suboption
118
162
  */
119
163
  const changeQuantity = (quantity) => {
120
164
  changeState({