@darkpos/pricing 1.0.99 → 1.0.100

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.
@@ -26,25 +26,18 @@ describe('Conditions not met for the item', () => {
26
26
  ],
27
27
  },
28
28
  };
29
- const conditionsBag = [];
30
29
  const { addItemModifier } = pricingService.order;
31
- addItemModifier({
32
- order,
33
- modifier,
34
- itemIndex: 0,
35
- onConditionsNotMet: bag => {
36
- bag.forEach(condition => {
37
- conditionsBag.push(condition);
38
- });
39
- },
40
- });
41
- expect(conditionsBag).toEqual([
42
- {
43
- current: 1,
44
- name: '$gt.itemPieces',
45
- value: 5,
46
- },
47
- ]);
30
+ const calculatedOrder = pricingService.order.calculate(
31
+ addItemModifier({
32
+ order,
33
+ modifier,
34
+ itemIndex: 0,
35
+ })
36
+ );
37
+ expect(calculatedOrder.items[0].modifiers.length).toEqual(1);
38
+ expect(calculatedOrder.items[0].modifiers[0].conditions.valid).toEqual(
39
+ false
40
+ );
48
41
  });
49
42
  test('#2: Item quantity condition is not met, errors bag populated', () => {
50
43
  const order = {
@@ -65,25 +58,19 @@ describe('Conditions not met for the item', () => {
65
58
  ],
66
59
  },
67
60
  };
68
- const conditionsBag = [];
69
61
  const { addItemModifier } = pricingService.order;
70
- addItemModifier({
71
- order,
72
- modifier,
73
- itemIndex: 0,
74
- onConditionsNotMet: bag => {
75
- bag.forEach(condition => {
76
- conditionsBag.push(condition);
77
- });
78
- },
79
- });
80
- expect(conditionsBag).toEqual([
81
- {
82
- current: 1,
83
- name: '$gt.itemQuantity',
84
- value: 5,
85
- },
86
- ]);
62
+ const calculatedOrder = pricingService.order.calculate(
63
+ addItemModifier({
64
+ order,
65
+ modifier,
66
+ itemIndex: 0,
67
+ })
68
+ );
69
+
70
+ expect(calculatedOrder.items[0].modifiers.length).toEqual(1);
71
+ expect(calculatedOrder.items[0].modifiers[0].conditions.valid).toEqual(
72
+ false
73
+ );
87
74
  });
88
75
  test('#3: Required modifiers condition is not met, errors bag populated', () => {
89
76
  const order = {
@@ -108,30 +95,20 @@ describe('Conditions not met for the item', () => {
108
95
  },
109
96
  ],
110
97
  },
98
+ _id: '123',
111
99
  };
112
- const conditionsBag = [];
113
100
  const { addItemModifier } = pricingService.order;
114
- addItemModifier({
115
- order,
116
- modifier,
117
- itemIndex: 0,
118
- onConditionsNotMet: bag => {
119
- bag.forEach(condition => {
120
- conditionsBag.push(condition);
121
- });
122
- },
123
- });
124
- expect(conditionsBag).toEqual([
125
- {
126
- current: [],
127
- name: '$in.modifiers',
128
- value: [
129
- {
130
- modifierId: 'mod-1',
131
- },
132
- ],
133
- },
134
- ]);
101
+ const calculatedOrder = pricingService.order.calculate(
102
+ addItemModifier({
103
+ order,
104
+ modifier,
105
+ itemIndex: 0,
106
+ })
107
+ );
108
+ expect(calculatedOrder.items[0].modifiers.length).toEqual(1);
109
+ expect(calculatedOrder.items[0].modifiers[0].conditions.valid).toEqual(
110
+ false
111
+ );
135
112
  });
136
113
 
137
114
  test('#4: Item number condition is met, errors bag empty', () => {
@@ -1008,4 +985,278 @@ describe('Conditions not met for the item', () => {
1008
985
  paymentId: undefined,
1009
986
  });
1010
987
  });
988
+
989
+ test('addModifiers should not be valid if the parent is not valid', () => {
990
+ const addModifier = {
991
+ _id: '6819114c06c23d37c1f19435',
992
+ name: 'Add Modifier',
993
+ type: 'discount',
994
+ tags: ['default'],
995
+ direct: true,
996
+ };
997
+ const modifier = {
998
+ _id: '6819114c06c23d37c1f19412',
999
+ name: 'parent modifier',
1000
+ type: 'discount',
1001
+ tags: ['default'],
1002
+ direct: true,
1003
+ conditions: {
1004
+ valid: null,
1005
+ rules: [
1006
+ {
1007
+ key: 'payment',
1008
+ value: 'prepay',
1009
+ operand: '$in',
1010
+ },
1011
+ ],
1012
+ },
1013
+ compute: {
1014
+ type: 'fixed',
1015
+ action: 'subtract',
1016
+ amount: 1,
1017
+ },
1018
+ addModifiers: [addModifier],
1019
+ };
1020
+
1021
+ const item = {
1022
+ _id: 'abc',
1023
+ price: 10,
1024
+ quantity: 1,
1025
+ modifiers: [],
1026
+ };
1027
+
1028
+ let order = {
1029
+ items: [item],
1030
+ };
1031
+
1032
+ order = pricingService.order.addItemModifier({
1033
+ order,
1034
+ modifier,
1035
+ itemIndex: 0,
1036
+ });
1037
+
1038
+ expect(order.items[0].modifiers.length).toBe(2);
1039
+
1040
+ const resultedOrder = pricingService.order.calculate(order);
1041
+
1042
+ expect(resultedOrder.items[0].modifiers[0].modifierId).toBe(
1043
+ '6819114c06c23d37c1f19412'
1044
+ );
1045
+ expect(resultedOrder.items[0].modifiers[0].name).toBe('parent modifier');
1046
+ expect(resultedOrder.items[0].modifiers[0].conditions.valid).toBe(false);
1047
+
1048
+ expect(resultedOrder.items[0].modifiers[1].modifierId).toBe(
1049
+ '6819114c06c23d37c1f19435'
1050
+ );
1051
+ expect(resultedOrder.items[0].modifiers[1].name).toBe('Add Modifier');
1052
+ expect(resultedOrder.items[0].modifiers[1].conditions.valid).toBe(false);
1053
+ });
1054
+
1055
+ test('delModifiers should be valid (remain untouched) if the parent is not valid', () => {
1056
+ const delModifier = {
1057
+ _id: '6819114c06c23d37c1f19435',
1058
+ name: 'Del Modifier',
1059
+ type: 'discount',
1060
+ tags: ['default'],
1061
+ direct: true,
1062
+ };
1063
+ const modifier = {
1064
+ _id: '6819114c06c23d37c1f19412',
1065
+ name: 'parent modifier',
1066
+ type: 'discount',
1067
+ tags: ['default'],
1068
+ direct: true,
1069
+ conditions: {
1070
+ valid: null,
1071
+ rules: [
1072
+ {
1073
+ key: 'payment',
1074
+ value: 'prepay',
1075
+ operand: '$in',
1076
+ },
1077
+ ],
1078
+ },
1079
+ compute: {
1080
+ type: 'fixed',
1081
+ action: 'subtract',
1082
+ amount: 1,
1083
+ },
1084
+ delModifier: [delModifier],
1085
+ };
1086
+
1087
+ const item = {
1088
+ _id: 'abc',
1089
+ price: 10,
1090
+ quantity: 1,
1091
+ modifiers: [],
1092
+ };
1093
+
1094
+ let order = {
1095
+ items: [item],
1096
+ };
1097
+
1098
+ order = pricingService.order.addItemModifier({
1099
+ order,
1100
+ modifier,
1101
+ itemIndex: 0,
1102
+ });
1103
+
1104
+ order = pricingService.order.addItemModifier({
1105
+ order,
1106
+ modifier: delModifier,
1107
+ itemIndex: 0,
1108
+ });
1109
+
1110
+ expect(order.items[0].modifiers.length).toBe(2);
1111
+
1112
+ const resultedOrder = pricingService.order.calculate(order);
1113
+
1114
+ expect(resultedOrder.items[0].modifiers[0].modifierId).toBe(
1115
+ '6819114c06c23d37c1f19412'
1116
+ );
1117
+ expect(resultedOrder.items[0].modifiers[0].name).toBe('parent modifier');
1118
+ expect(resultedOrder.items[0].modifiers[0].conditions.valid).toBe(false);
1119
+
1120
+ expect(resultedOrder.items[0].modifiers[1].modifierId).toBe(
1121
+ '6819114c06c23d37c1f19435'
1122
+ );
1123
+ expect(resultedOrder.items[0].modifiers[1].name).toBe('Del Modifier');
1124
+ expect(resultedOrder.items[0].modifiers[1].conditions.valid).toBe(true);
1125
+ });
1126
+
1127
+ test('delModifiers should be invalid if the parent is valid', () => {
1128
+ const delModifier = {
1129
+ _id: '6819114c06c23d37c1f19435',
1130
+ name: 'Del Modifier',
1131
+ type: 'discount',
1132
+ tags: ['default'],
1133
+ direct: true,
1134
+ };
1135
+ const modifier = {
1136
+ _id: '6819114c06c23d37c1f19412',
1137
+ name: 'parent modifier',
1138
+ type: 'discount',
1139
+ tags: ['default'],
1140
+ direct: true,
1141
+ conditions: {
1142
+ valid: null,
1143
+ rules: [
1144
+ {
1145
+ key: 'payment',
1146
+ value: 'prepay',
1147
+ operand: '$in',
1148
+ },
1149
+ ],
1150
+ },
1151
+ compute: {
1152
+ type: 'fixed',
1153
+ action: 'subtract',
1154
+ amount: 1,
1155
+ },
1156
+ delModifiers: [delModifier],
1157
+ };
1158
+
1159
+ const item = {
1160
+ _id: 'abc',
1161
+ price: 10,
1162
+ quantity: 1,
1163
+ modifiers: [],
1164
+ };
1165
+
1166
+ let order = {
1167
+ items: [item],
1168
+ };
1169
+
1170
+ order = pricingService.order.addItemModifier({
1171
+ order,
1172
+ modifier,
1173
+ itemIndex: 0,
1174
+ });
1175
+
1176
+ order = pricingService.order.addItemModifier({
1177
+ order,
1178
+ modifier: delModifier,
1179
+ itemIndex: 0,
1180
+ });
1181
+
1182
+ expect(order.items[0].modifiers.length).toBe(2);
1183
+
1184
+ const resultedOrder = pricingService.order.calculate(order, {
1185
+ isPrepay: true,
1186
+ });
1187
+
1188
+ expect(resultedOrder.items[0].modifiers[0].modifierId).toBe(
1189
+ '6819114c06c23d37c1f19412'
1190
+ );
1191
+ expect(resultedOrder.items[0].modifiers[0].name).toBe('parent modifier');
1192
+ expect(resultedOrder.items[0].modifiers[0].conditions.valid).toBe(true);
1193
+
1194
+ expect(resultedOrder.items[0].modifiers[1].modifierId).toBe(
1195
+ '6819114c06c23d37c1f19435'
1196
+ );
1197
+ expect(resultedOrder.items[0].modifiers[1].name).toBe('Del Modifier');
1198
+ expect(resultedOrder.items[0].modifiers[1].conditions.valid).toBe(false);
1199
+ });
1200
+
1201
+ test('addModifiers should not be deleted if the parent gets deleted', () => {
1202
+ const addModifier = {
1203
+ _id: '6819114c06c23d37c1f19435',
1204
+ name: 'Add Modifier',
1205
+ type: 'discount',
1206
+ tags: ['default'],
1207
+ direct: true,
1208
+ };
1209
+ const modifier = {
1210
+ _id: '6819114c06c23d37c1f19412',
1211
+ name: 'parent modifier',
1212
+ type: 'discount',
1213
+ tags: ['default'],
1214
+ direct: true,
1215
+ conditions: {
1216
+ valid: null,
1217
+ rules: [
1218
+ {
1219
+ key: 'payment',
1220
+ value: 'prepay',
1221
+ operand: '$in',
1222
+ },
1223
+ ],
1224
+ },
1225
+ compute: {
1226
+ type: 'fixed',
1227
+ action: 'subtract',
1228
+ amount: 1,
1229
+ },
1230
+ addModifiers: [addModifier],
1231
+ };
1232
+
1233
+ const item = {
1234
+ _id: 'abc',
1235
+ price: 10,
1236
+ quantity: 1,
1237
+ modifiers: [],
1238
+ };
1239
+
1240
+ let order = {
1241
+ items: [item],
1242
+ };
1243
+
1244
+ order = pricingService.order.addItemModifier({
1245
+ order,
1246
+ modifier,
1247
+ itemIndex: 0,
1248
+ });
1249
+
1250
+ expect(order.items[0].modifiers.length).toBe(2);
1251
+
1252
+ const parentModifier = order.items[0].modifiers[0];
1253
+
1254
+ const result = pricingService.item.removeModifier({
1255
+ item: order.items[0],
1256
+ modifier: parentModifier,
1257
+ order,
1258
+ });
1259
+
1260
+ expect(result.modifiers.length).toBe(0);
1261
+ });
1011
1262
  });
@@ -1106,7 +1106,7 @@ describe('Order actions', () => {
1106
1106
 
1107
1107
  test('Applies fixed and percentage discounts with fixed modifier added first (both payment modifiers)', () => {
1108
1108
  const prePayDiscount1Usd = {
1109
- _id: '6819114c06c23d37c1f19412',
1109
+ _id: '6819114c06c23d37c55522',
1110
1110
  name: '1 usd pre pay disc',
1111
1111
  type: 'discount',
1112
1112
  tags: ['default'],
@@ -1129,7 +1129,7 @@ describe('Order actions', () => {
1129
1129
  };
1130
1130
 
1131
1131
  const cashDiscount10Percent = {
1132
- _id: '6819114c06c23d37c1f19412',
1132
+ _id: '6819114c06c23d37c1f4543',
1133
1133
  name: '10 % cash discount',
1134
1134
  type: 'discount',
1135
1135
  tags: ['default'],
@@ -1177,7 +1177,7 @@ describe('Order actions', () => {
1177
1177
 
1178
1178
  test('Applies percentage and fixed discounts with percentage modifier added first (both paymentModifiers)', () => {
1179
1179
  const prePayDiscount1Usd = {
1180
- _id: '6819114c06c23d37c1f19412',
1180
+ _id: '6819114c06c23d37c1f22233',
1181
1181
  name: '1 usd pre pay disc',
1182
1182
  type: 'discount',
1183
1183
  tags: ['default'],
@@ -1200,7 +1200,7 @@ describe('Order actions', () => {
1200
1200
  };
1201
1201
 
1202
1202
  const cashDiscount10Percent = {
1203
- _id: '6819114c06c23d37c1f19412',
1203
+ _id: '6819114c06c23d3744544',
1204
1204
  name: '10 % cash discount',
1205
1205
  type: 'discount',
1206
1206
  tags: ['default'],
@@ -1265,7 +1265,7 @@ describe('Order actions', () => {
1265
1265
  };
1266
1266
 
1267
1267
  const cashDiscount10Percent = {
1268
- _id: '6819114c06c23d37c1f19412',
1268
+ _id: '6819114c06c23d37c9999',
1269
1269
  name: '10 % cash discount',
1270
1270
  type: 'discount',
1271
1271
  tags: ['default'],
@@ -1312,7 +1312,7 @@ describe('Order actions', () => {
1312
1312
 
1313
1313
  test('Applies one payment discount and one regular percentage discount (fixed first)', () => {
1314
1314
  const prePayDiscount1Usd = {
1315
- _id: '6819114c06c23d37c1f19412',
1315
+ _id: '6819114c06c23d37c1f194444',
1316
1316
  name: '1 usd pre pay disc',
1317
1317
  type: 'discount',
1318
1318
  tags: ['default'],
@@ -1329,7 +1329,7 @@ describe('Order actions', () => {
1329
1329
  };
1330
1330
 
1331
1331
  const cashDiscount10Percent = {
1332
- _id: '6819114c06c23d37c1f19412',
1332
+ _id: '6819114c06c23d37c1f1555',
1333
1333
  name: '10 % cash discount',
1334
1334
  type: 'discount',
1335
1335
  tags: ['default'],
@@ -1376,7 +1376,7 @@ describe('Order actions', () => {
1376
1376
 
1377
1377
  test('Applies one payment discount and one regular percentage discount (fixed first) withouth sending amountToPay', () => {
1378
1378
  const prePayDiscount1Usd = {
1379
- _id: '6819114c06c23d37c1f19412',
1379
+ _id: '6819114c06c23d37c1f19234',
1380
1380
  name: '1 usd pre pay disc',
1381
1381
  type: 'discount',
1382
1382
  tags: ['default'],
@@ -1390,6 +1390,7 @@ describe('Order actions', () => {
1390
1390
  action: 'subtract',
1391
1391
  amount: 1,
1392
1392
  },
1393
+ modifierId: '321545',
1393
1394
  };
1394
1395
 
1395
1396
  const cashDiscount10Percent = {
@@ -1413,6 +1414,7 @@ describe('Order actions', () => {
1413
1414
  action: 'subtract',
1414
1415
  amount: 10,
1415
1416
  },
1417
+ modifierId: '3232332',
1416
1418
  };
1417
1419
 
1418
1420
  const item = {
@@ -14,6 +14,7 @@ describe('Order actions', () => {
14
14
  test('Get calculated Order, one item', () => {
15
15
  const modifiers = [
16
16
  {
17
+ _id: '1123213',
17
18
  compute: {
18
19
  amount: 20,
19
20
  type: 'percentage',
@@ -26,6 +27,7 @@ describe('Order actions', () => {
26
27
  },
27
28
  },
28
29
  {
30
+ _id: '22222',
29
31
  compute: {
30
32
  amount: 20,
31
33
  type: 'percentage',
@@ -38,6 +40,7 @@ describe('Order actions', () => {
38
40
  },
39
41
  },
40
42
  {
43
+ _id: '333',
41
44
  compute: { amount: 2, type: 'fixed', action: 'subtract' },
42
45
  name: 'modifier3',
43
46
  type: 'discount',
@@ -2822,7 +2825,7 @@ describe('Order actions', () => {
2822
2825
  _id: 1,
2823
2826
  price: 10,
2824
2827
  quantity: 1,
2825
- modifiers: [discountMod100Fixed, discountMod100Fixed],
2828
+ modifiers: [discountMod100Fixed, { ...discountMod100Fixed, _id: 222 }],
2826
2829
  };
2827
2830
 
2828
2831
  const calculatedItem = pricingService.item.calculate(item1);
@@ -2865,7 +2868,7 @@ describe('Order actions', () => {
2865
2868
  _id: 1,
2866
2869
  price: 10,
2867
2870
  quantity: 2,
2868
- modifiers: [discountMod100Fixed, discountMod100Fixed],
2871
+ modifiers: [discountMod100Fixed, { ...discountMod100Fixed, _id: 222 }],
2869
2872
  };
2870
2873
 
2871
2874
  const calculatedItem = pricingService.item.calculate(item1);
@@ -2911,7 +2914,10 @@ describe('Order actions', () => {
2911
2914
  _id: 1,
2912
2915
  price: 10,
2913
2916
  quantity: 2,
2914
- modifiers: [discountMod100Percentage, discountMod100Percentage],
2917
+ modifiers: [
2918
+ discountMod100Percentage,
2919
+ { ...discountMod100Percentage, _id: 2 },
2920
+ ],
2915
2921
  };
2916
2922
 
2917
2923
  const calculatedItem = pricingService.item.calculate(item1);
@@ -2940,7 +2946,7 @@ describe('Order actions', () => {
2940
2946
 
2941
2947
  test('CU-861n7pum9 - Calculate order -> discountMod100Percentage discountMod100Fixed qt=2', () => {
2942
2948
  const discountMod100Percentage = {
2943
- _id: 1,
2949
+ _id: 2222,
2944
2950
  compute: {
2945
2951
  amount: 100,
2946
2952
  type: 'percentage',
@@ -2954,7 +2960,7 @@ describe('Order actions', () => {
2954
2960
  };
2955
2961
 
2956
2962
  const discountMod100Fixed = {
2957
- _id: 1,
2963
+ _id: 333333,
2958
2964
  compute: {
2959
2965
  amount: 100,
2960
2966
  type: 'fixed',
@@ -2971,8 +2977,8 @@ describe('Order actions', () => {
2971
2977
  modifiers: [
2972
2978
  discountMod100Percentage,
2973
2979
  discountMod100Fixed,
2974
- discountMod100Percentage,
2975
- discountMod100Fixed,
2980
+ { ...discountMod100Percentage, _id: 4444 },
2981
+ { ...discountMod100Fixed, _id: 5555 },
2976
2982
  ],
2977
2983
  };
2978
2984
 
@@ -3002,7 +3008,7 @@ describe('Order actions', () => {
3002
3008
 
3003
3009
  test('CU-861n7pum9 - Calculate order -> discountMod60Percentage discountMod100Fixed, sort, qt=2', () => {
3004
3010
  const discountMod60Percentage = {
3005
- _id: 1,
3011
+ _id: 222,
3006
3012
  compute: {
3007
3013
  amount: 60,
3008
3014
  type: 'percentage',
@@ -3017,7 +3023,7 @@ describe('Order actions', () => {
3017
3023
  };
3018
3024
 
3019
3025
  const discountMod100Fixed = {
3020
- _id: 1,
3026
+ _id: 3333,
3021
3027
  compute: {
3022
3028
  amount: 100,
3023
3029
  type: 'fixed',
@@ -3063,7 +3069,7 @@ describe('Order actions', () => {
3063
3069
 
3064
3070
  test('CU-861n7pum9 - Calculate order -> discountMod9Fixed , sort, qt=2', () => {
3065
3071
  const discountMod9Fixed = {
3066
- _id: 1,
3072
+ _id: 11111,
3067
3073
  compute: {
3068
3074
  amount: 12,
3069
3075
  type: 'fixed',
@@ -3077,10 +3083,10 @@ describe('Order actions', () => {
3077
3083
  };
3078
3084
 
3079
3085
  const item1 = {
3080
- _id: 1,
3086
+ _id: 22222,
3081
3087
  price: 10,
3082
3088
  quantity: 2,
3083
- modifiers: [discountMod9Fixed, discountMod9Fixed],
3089
+ modifiers: [discountMod9Fixed, { ...discountMod9Fixed, _id: 5555 }],
3084
3090
  };
3085
3091
 
3086
3092
  const calculatedItem = pricingService.item.calculate(item1);
@@ -52,17 +52,16 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
52
52
  modifierActions.isLocked(mod)
53
53
  );
54
54
 
55
- const validatedModifiers = itemModifiers.map(each =>
56
- modifierActions.validate(each, {
57
- item,
58
- startRequestDate,
59
- endRequestDate,
60
- allItems,
61
- paymentMethod,
62
- paymentType,
63
- isPrepay,
64
- })
65
- );
55
+ const validatedModifiers = actions.validateModifiers({
56
+ item,
57
+ itemModifiers,
58
+ startRequestDate,
59
+ endRequestDate,
60
+ allItems,
61
+ paymentMethod,
62
+ paymentType,
63
+ isPrepay,
64
+ });
66
65
 
67
66
  const modifiersToCompute = validatedModifiers.filter(
68
67
  each =>
package/lib/item/index.js CHANGED
@@ -65,6 +65,7 @@ const getUpdatedStatus = require('./getUpdatedStatus');
65
65
  const isOverwrittenPrice = require('./isOverwrittenPrice');
66
66
  const isOverwrittenQuantity = require('./isOverwrittenQuantity');
67
67
  const overrideNotes = require('./overrideNotes');
68
+ const validateModifiers = require('./validateModifiers');
68
69
 
69
70
  const itemActions = (deps = {}) => {
70
71
  const actions = {};
@@ -143,6 +144,7 @@ const itemActions = (deps = {}) => {
143
144
  isOverwrittenPrice: isOverwrittenPrice(innerDeps),
144
145
  isOverwrittenQuantity: isOverwrittenQuantity(innerDeps),
145
146
  overrideNotes: overrideNotes(innerDeps),
147
+ validateModifiers: validateModifiers(innerDeps),
146
148
  });
147
149
 
148
150
  Object.keys(freezedActions).forEach(actionName => {
@@ -15,24 +15,21 @@ module.exports = ({ modifierActions, _, actions }) => {
15
15
 
16
16
  const modifiersToApply = [
17
17
  modifier,
18
- ...addModifiers.filter(
19
- addMod =>
20
- !addMod.required &&
21
- (!order ||
22
- !actions.hasModifier({
23
- item: {
24
- ...item,
25
- modifiers: item.modifiers.filter(
26
- mod => mod._id !== modifier._id
27
- ),
28
- },
29
- modifier: addMod,
30
- relatedItems: actions.getRelatedItems({
31
- items: order.items,
32
- item,
33
- }),
34
- }))
35
- ),
18
+ ...addModifiers.filter(addMod => {
19
+ if (addMod.required) return false;
20
+ const hasModifier = actions.hasModifier({
21
+ item: {
22
+ ...item,
23
+ modifiers: item.modifiers.filter(mod => mod._id !== modifier._id),
24
+ },
25
+ modifier: addMod,
26
+ relatedItems: actions.getRelatedItems({
27
+ items: order ? order.items : [],
28
+ item,
29
+ }),
30
+ });
31
+ return modifierActions.isGroup(addMod) ? !hasModifier : !!hasModifier;
32
+ }),
36
33
  ];
37
34
 
38
35
  // Remove