@darkpos/pricing 1.0.79 → 1.0.81

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 (38) hide show
  1. package/__TEST__/modifier.test.js +584 -15
  2. package/__TEST__/order/conditionsNotMet.test.js +204 -0
  3. package/__TEST__/order/order.test.js +61 -8
  4. package/lib/item/adjustCreditModifiersDifference.js +34 -0
  5. package/lib/item/adjustFixedModifiersDifference.js +37 -0
  6. package/lib/item/getItemsTotals.js +2 -2
  7. package/lib/item/getModifierTags.js +1 -1
  8. package/lib/item/getSubtotal.js +5 -0
  9. package/lib/item/index.js +14 -0
  10. package/lib/item/removeModifiersByQuantity.js +5 -4
  11. package/lib/item/splitAndCalculate.js +18 -0
  12. package/lib/item/spreadModifiers.js +21 -0
  13. package/lib/item/validateCreditModifiersTotal.js +23 -0
  14. package/lib/item/validateFixedModifiersTotal.js +23 -0
  15. package/lib/modifier/areConditionsMet.js +13 -10
  16. package/lib/modifier/getCreditModifiersTotalEntities.js +12 -0
  17. package/lib/modifier/getFixedModifiersTotalEntities.js +12 -0
  18. package/lib/modifier/getMaxItemQuantity.js +5 -0
  19. package/lib/modifier/getMaxItemUse.js +5 -0
  20. package/lib/modifier/getMaxOrderUse.js +5 -0
  21. package/lib/modifier/getSplittedModifiers.js +15 -30
  22. package/lib/modifier/index.js +16 -8
  23. package/lib/modifier/isOrderUseValid.js +25 -0
  24. package/lib/modifier/isUnlimitedItemUse.js +4 -0
  25. package/lib/modifier/isUnlimitedOrderUse.js +4 -0
  26. package/lib/order/addItemModifier.js +27 -4
  27. package/lib/order/addModifier.js +8 -18
  28. package/lib/order/index.js +2 -4
  29. package/lib/order/splitItems.js +50 -0
  30. package/lib/order/validateCreditModifiersTotal.js +1 -1
  31. package/lib/order/validateFixedModifiersTotal.js +1 -1
  32. package/package.json +2 -2
  33. package/lib/modifier/getMaxAppliesItem.js +0 -5
  34. package/lib/modifier/getMaxAppliesOrder.js +0 -5
  35. package/lib/modifier/isUnlimitedAppliesItem.js +0 -6
  36. package/lib/modifier/isUnlimitedAppliesOrder.js +0 -6
  37. package/lib/order/getCreditModifiersTotal.js +0 -15
  38. package/lib/order/getFixedModifiersTotal.js +0 -15
@@ -680,4 +680,208 @@ describe('Conditions not met for the item', () => {
680
680
  expect(order.items[5].total).toBe(5);
681
681
  expect(order.items[5].modifiers.length).toBe(1);
682
682
  });
683
+
684
+ test('#8: Item number condition is met using aggregatedItems, rule is lastSelected', () => {
685
+ const mod3x2 = {
686
+ _id: '68069a18766f8687858461e7',
687
+ name: '3x2',
688
+ properties: {},
689
+ type: 'discount',
690
+ tags: ['default'],
691
+ conditions: {
692
+ valid: null,
693
+ rules: [
694
+ {
695
+ key: 'itemSet',
696
+ value: { itemSet: '3', itemRule: 'lastSelected' },
697
+ operand: '$eq',
698
+ },
699
+ ],
700
+ },
701
+ compute: {
702
+ type: 'percentage',
703
+ action: 'subtract',
704
+ amount: 100,
705
+ },
706
+ };
707
+
708
+ const item = {
709
+ _id: 'abc',
710
+ price: 10,
711
+ quantity: 3,
712
+ };
713
+
714
+ let order = {
715
+ id: 'ord-123',
716
+ items: [],
717
+ modifiers: [],
718
+ };
719
+
720
+ order = pricingService.order.addItem({
721
+ order,
722
+ item,
723
+ }).updatedOrder;
724
+
725
+ order = pricingService.order.addItemModifier({
726
+ order,
727
+ modifier: mod3x2,
728
+ itemIndex: 0,
729
+ });
730
+
731
+ expect(order.items.length).toEqual(1);
732
+
733
+ order = pricingService.order.calculate(order);
734
+
735
+ expect(order.total).toBe(20);
736
+ expect(order.items[0].total).toBe(20);
737
+ expect(order.items[0].modifiers.length).toBe(1);
738
+ });
739
+
740
+ test('#9: Item number condition is met using aggregatedItems and others, rule is lastSelected', () => {
741
+ const mod3x2 = {
742
+ _id: '68069a18766f8687858461e7',
743
+ name: '3x2',
744
+ properties: {},
745
+ type: 'discount',
746
+ tags: ['default'],
747
+ conditions: {
748
+ valid: null,
749
+ rules: [
750
+ {
751
+ key: 'itemSet',
752
+ value: { itemSet: '3', itemRule: 'lastSelected' },
753
+ operand: '$eq',
754
+ },
755
+ ],
756
+ },
757
+ compute: {
758
+ type: 'percentage',
759
+ action: 'subtract',
760
+ amount: 100,
761
+ },
762
+ };
763
+
764
+ const item = {
765
+ _id: 'abc',
766
+ price: 10,
767
+ quantity: 2,
768
+ };
769
+
770
+ const item2 = {
771
+ _id: 'bcd',
772
+ price: 10,
773
+ quantity: 1,
774
+ };
775
+
776
+ let order = {
777
+ id: 'ord-123',
778
+ items: [],
779
+ modifiers: [],
780
+ };
781
+
782
+ order = pricingService.order.addItem({
783
+ order,
784
+ item,
785
+ }).updatedOrder;
786
+ order = pricingService.order.addItemModifier({
787
+ order,
788
+ modifier: mod3x2,
789
+ itemIndex: 0,
790
+ });
791
+
792
+ order = pricingService.order.addItem({
793
+ order,
794
+ item: item2,
795
+ }).updatedOrder;
796
+
797
+ order = pricingService.order.addItemModifier({
798
+ order,
799
+ modifier: mod3x2,
800
+ itemIndex: 0,
801
+ });
802
+
803
+ expect(order.items.length).toEqual(2);
804
+
805
+ order = pricingService.order.calculate(order);
806
+
807
+ expect(order.total).toBe(20);
808
+ expect(order.items[0].total).toBe(0);
809
+ expect(order.items[0].modifiers.length).toBe(1);
810
+ expect(order.items[1].total).toBe(20);
811
+ expect(order.items[1].modifiers.length).toBe(1);
812
+ });
813
+
814
+ test('#10: Item number condition is met using aggregatedItems and others, rule is lastSelected', () => {
815
+ const mod3x2 = {
816
+ _id: '68069a18766f8687858461e7',
817
+ name: '3x2',
818
+ properties: {},
819
+ type: 'discount',
820
+ tags: ['default'],
821
+ conditions: {
822
+ valid: null,
823
+ rules: [
824
+ {
825
+ key: 'itemSet',
826
+ value: { itemSet: '3', itemRule: 'lastSelected' },
827
+ operand: '$eq',
828
+ },
829
+ ],
830
+ },
831
+ compute: {
832
+ type: 'percentage',
833
+ action: 'subtract',
834
+ amount: 100,
835
+ },
836
+ };
837
+
838
+ const item = {
839
+ _id: 'abc',
840
+ price: 10,
841
+ quantity: 3,
842
+ };
843
+
844
+ const item2 = {
845
+ _id: 'bcd',
846
+ price: 10,
847
+ quantity: 3,
848
+ };
849
+
850
+ let order = {
851
+ id: 'ord-123',
852
+ items: [],
853
+ modifiers: [],
854
+ };
855
+
856
+ order = pricingService.order.addItem({
857
+ order,
858
+ item,
859
+ }).updatedOrder;
860
+ order = pricingService.order.addItemModifier({
861
+ order,
862
+ modifier: mod3x2,
863
+ itemIndex: 0,
864
+ });
865
+
866
+ order = pricingService.order.addItem({
867
+ order,
868
+ item: item2,
869
+ }).updatedOrder;
870
+
871
+ order = pricingService.order.addItemModifier({
872
+ order,
873
+ modifier: mod3x2,
874
+ itemIndex: 0,
875
+ });
876
+
877
+ expect(order.items.length).toEqual(2);
878
+
879
+ order = pricingService.order.calculate(order);
880
+
881
+ expect(order.total).toBe(40);
882
+ expect(order.items[0].total).toBe(20);
883
+ expect(order.items[0].modifiers.length).toBe(1);
884
+ expect(order.items[1].total).toBe(20);
885
+ expect(order.items[1].modifiers.length).toBe(1);
886
+ });
683
887
  });
@@ -3700,7 +3700,7 @@ describe('Order actions', () => {
3700
3700
  expect(splittedOrders[1].items[0].quantity).toEqual(6);
3701
3701
  });
3702
3702
 
3703
- test('CU-86dve295v Should continue to add a modifier while its quantity is less than the specified in properties.limits.maxAppliesOrder=5', () => {
3703
+ test('CU-86dve295v Should add a modifier just once at order level even if properties.limits.maxOrderUse=5', () => {
3704
3704
  const order = {
3705
3705
  id: 'ord-123',
3706
3706
  items: [],
@@ -3715,7 +3715,7 @@ describe('Order actions', () => {
3715
3715
  },
3716
3716
  modifierId: 'abc123',
3717
3717
  properties: {
3718
- limits: { maxAppliesOrder: 5 },
3718
+ limits: { maxOrderUse: 5 },
3719
3719
  },
3720
3720
  };
3721
3721
  order.items.push({
@@ -3734,10 +3734,10 @@ describe('Order actions', () => {
3734
3734
  });
3735
3735
  }
3736
3736
 
3737
- expect(currentOrder.modifiers.length).toBe(5);
3737
+ expect(currentOrder.modifiers.length).toBe(1);
3738
3738
  });
3739
3739
 
3740
- test('CU-86dve295v Should continue to add a modifier if properties.limits.isUnlimitedAppliesOrder=true', () => {
3740
+ test('CU-86dve295v Should add the modifier just once at order level even if properties.limits.maxOrderUse=-1', () => {
3741
3741
  const order = {
3742
3742
  id: 'ord-123',
3743
3743
  items: [],
@@ -3752,7 +3752,7 @@ describe('Order actions', () => {
3752
3752
  },
3753
3753
  modifierId: 'abc123',
3754
3754
  properties: {
3755
- limits: { isUnlimitedAppliesOrder: true },
3755
+ limits: { maxOrderUse: -1 },
3756
3756
  },
3757
3757
  };
3758
3758
  order.items.push({
@@ -3771,10 +3771,10 @@ describe('Order actions', () => {
3771
3771
  });
3772
3772
  }
3773
3773
 
3774
- expect(currentOrder.modifiers.length).toBe(5);
3774
+ expect(currentOrder.modifiers.length).toBe(1);
3775
3775
  });
3776
3776
 
3777
- test('CU-86dve295v Should not add a modifier more than once if properties.limits.isUnlimitedAppliesOrder=false and properties.limits.maxAppliesOrder is not defined', () => {
3777
+ test('CU-86dve295v Should not add a modifier more than once if properties.limits.maxOrderUse is not defined', () => {
3778
3778
  const order = {
3779
3779
  id: 'ord-123',
3780
3780
  items: [],
@@ -3789,7 +3789,7 @@ describe('Order actions', () => {
3789
3789
  },
3790
3790
  modifierId: 'abc123',
3791
3791
  properties: {
3792
- limits: { isUnlimitedAppliesOrder: false, maxAppliesOrder: 0 },
3792
+ limits: { maxOrderUse: 0 },
3793
3793
  },
3794
3794
  };
3795
3795
  order.items.push({
@@ -3810,4 +3810,57 @@ describe('Order actions', () => {
3810
3810
 
3811
3811
  expect(currentOrder.modifiers.length).toBe(1);
3812
3812
  });
3813
+
3814
+ test('CU-86dve295v Should add to modifiers at order level', () => {
3815
+ const order = {
3816
+ id: 'ord-123',
3817
+ items: [],
3818
+ modifiers: [],
3819
+ };
3820
+ const modifier = {
3821
+ _id: 1,
3822
+ compute: {
3823
+ amount: 10,
3824
+ action: 'subtract',
3825
+ type: 'fixed',
3826
+ },
3827
+ modifierId: 'abc123',
3828
+ properties: {
3829
+ limits: { maxOrderUse: 0 },
3830
+ },
3831
+ };
3832
+
3833
+ const modifier2 = {
3834
+ _id: 2,
3835
+ compute: {
3836
+ amount: 10,
3837
+ action: 'subtract',
3838
+ type: 'fixed',
3839
+ },
3840
+ modifierId: 'abc123',
3841
+ };
3842
+
3843
+ order.items.push({
3844
+ quantity: 2,
3845
+ itemId: '123',
3846
+ price: 100,
3847
+ modifiers: [],
3848
+ });
3849
+
3850
+ let currentOrder = { ...order };
3851
+
3852
+ for (let i = 0; i < 5; i += 1) {
3853
+ currentOrder = pricingService.order.addModifier({
3854
+ order: currentOrder,
3855
+ modifier,
3856
+ });
3857
+ }
3858
+
3859
+ currentOrder = pricingService.order.addModifier({
3860
+ order: currentOrder,
3861
+ modifier: modifier2,
3862
+ });
3863
+
3864
+ expect(currentOrder.modifiers.length).toBe(2);
3865
+ });
3813
3866
  });
@@ -0,0 +1,34 @@
1
+ module.exports = ({ utils, actions, modifierActions }) => {
2
+ const { math } = utils;
3
+
4
+ return function adjustCreditModifiersDifference({ subItems, difference }) {
5
+ const selectedSubItemIndex = subItems.findIndex(
6
+ subItem =>
7
+ modifierActions.hasCreditModifier(subItem.modifiers) &&
8
+ !actions.isFullyPaid(subItem) &&
9
+ subItem.total > difference
10
+ );
11
+
12
+ if (selectedSubItemIndex !== -1) {
13
+ const subItemToUpdate = {
14
+ ...subItems[selectedSubItemIndex],
15
+ };
16
+ const modifierToUpdateIdx = subItemToUpdate.modifiers.findIndex(
17
+ mod => mod.type === 'credit'
18
+ );
19
+ const prevAmount =
20
+ subItemToUpdate.modifiers[modifierToUpdateIdx].properties.maxAmount;
21
+
22
+ subItemToUpdate.modifiers[modifierToUpdateIdx].properties.maxAmount =
23
+ math.add(prevAmount, difference);
24
+
25
+ subItems.splice(
26
+ selectedSubItemIndex,
27
+ 1,
28
+ actions.calculate(subItemToUpdate)
29
+ );
30
+ }
31
+
32
+ return subItems;
33
+ };
34
+ };
@@ -0,0 +1,37 @@
1
+ module.exports = ({ utils, actions, modifierActions, _ }) => {
2
+ const { math } = utils;
3
+ const { getComputeModField } = require('../modifier/utils');
4
+ return function adjustFixedModifiersDifference({ subItems, difference }) {
5
+ const selectedSubItemIndex = subItems.findIndex(
6
+ subItem =>
7
+ modifierActions.hasFixedModifier(subItem.modifiers) &&
8
+ !actions.isFullyPaid(subItem) &&
9
+ subItem.total > difference
10
+ );
11
+
12
+ if (selectedSubItemIndex !== -1) {
13
+ const subItemToUpdate = {
14
+ ...subItems[selectedSubItemIndex],
15
+ };
16
+
17
+ const modifierToUpdateIdx = subItemToUpdate.modifiers.findIndex(
18
+ mod => mod.compute && mod.compute.type === 'fixed'
19
+ );
20
+ const prevCompute = getComputeModField(
21
+ subItemToUpdate.modifiers[modifierToUpdateIdx]
22
+ );
23
+ const prevAmount = _.get(prevCompute, 'compute.amount', 0);
24
+ if (modifierToUpdateIdx !== -1) {
25
+ subItemToUpdate.modifiers[modifierToUpdateIdx].compute.amount =
26
+ math.add(prevAmount, difference);
27
+ }
28
+ subItems.splice(
29
+ selectedSubItemIndex,
30
+ 1,
31
+ actions.calculate(subItemToUpdate)
32
+ );
33
+ }
34
+
35
+ return subItems;
36
+ };
37
+ };
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
2
 
3
- module.exports = ({ utils }) => {
3
+ module.exports = ({ utils, actions }) => {
4
4
  const { math } = utils;
5
5
  return function getItemsTotals(items) {
6
6
  const subTotals = {};
@@ -8,7 +8,7 @@ module.exports = ({ utils }) => {
8
8
  let total = 0;
9
9
 
10
10
  for (const item of items) {
11
- subTotal = math.add(subTotal, item.subTotals._actual);
11
+ subTotal = math.add(subTotal, actions.getSubtotal(item));
12
12
  const keys = Object.keys(item.subTotals).filter(
13
13
  key => !key.includes('_')
14
14
  );
@@ -8,7 +8,7 @@ module.exports = ({ modifierActions, settings }) =>
8
8
  let modifierTags = item.modifiers
9
9
  .filter(
10
10
  each =>
11
- (modifierActions.isValid(each) || modifierActions.isItemSet(each)) &&
11
+ modifierActions.isValid(each) &&
12
12
  (!modifierActions.isGroup(each) || modifierActions.isDepartment(each))
13
13
  )
14
14
 
@@ -0,0 +1,5 @@
1
+ module.exports = () =>
2
+ function getSubtotal(item) {
3
+ if (!item || !item.subTotals) return 0;
4
+ return item.subTotals._actual || 0;
5
+ };
package/lib/item/index.js CHANGED
@@ -52,6 +52,13 @@ const getAddModifiers = require('./getAddModifiers');
52
52
  const getRelatedItems = require('./getRelatedItems');
53
53
  const getRelatedModifiers = require('./getRelatedModifiers');
54
54
  const unpickItem = require('./unpick');
55
+ const spreadModifiers = require('./spreadModifiers');
56
+ const splitAndCalculate = require('./splitAndCalculate');
57
+ const validateFixedModifiersTotal = require('./validateFixedModifiersTotal');
58
+ const adjustFixedModifiersDifference = require('./adjustFixedModifiersDifference');
59
+ const validateCreditModifiersTotal = require('./validateCreditModifiersTotal');
60
+ const adjustCreditModifiersDifference = require('./adjustCreditModifiersDifference');
61
+ const getSubtotal = require('./getSubtotal');
55
62
 
56
63
  const itemActions = (deps = {}) => {
57
64
  const actions = {};
@@ -117,6 +124,13 @@ const itemActions = (deps = {}) => {
117
124
  getRelatedItems: getRelatedItems(innerDeps),
118
125
  getRelatedModifiers: getRelatedModifiers(innerDeps),
119
126
  unpickItem: unpickItem(innerDeps),
127
+ spreadModifiers: spreadModifiers(innerDeps),
128
+ splitAndCalculate: splitAndCalculate(innerDeps),
129
+ validateFixedModifiersTotal: validateFixedModifiersTotal(innerDeps),
130
+ adjustFixedModifiersDifference: adjustFixedModifiersDifference(innerDeps),
131
+ validateCreditModifiersTotal: validateCreditModifiersTotal(innerDeps),
132
+ adjustCreditModifiersDifference: adjustCreditModifiersDifference(innerDeps),
133
+ getSubtotal: getSubtotal(innerDeps),
120
134
  });
121
135
 
122
136
  Object.keys(freezedActions).forEach(actionName => {
@@ -1,4 +1,4 @@
1
- module.exports = ({ modifierActions }) =>
1
+ module.exports = ({ modifierActions, utils }) =>
2
2
  function removeModifiersByQuantity(item) {
3
3
  if (!item || !Array.isArray(item.modifiers)) {
4
4
  return item;
@@ -15,14 +15,15 @@ module.exports = ({ modifierActions }) =>
15
15
  modifierActions.isGroupOfModifiers(modifier) ||
16
16
  !modifier.modifierId ||
17
17
  !modifierActions.isDirect(modifier) ||
18
- modifierActions.isUnlimitedAppliesItem(modifier)
18
+ modifierActions.isUnlimitedItemUse(modifier)
19
19
  )
20
20
  return true;
21
21
 
22
22
  const count = modifierCounts[modifier.modifierId] || 0;
23
23
 
24
- const maxApplies = modifierActions.getMaxAppliesItem(modifier);
25
- const maxQuantity = maxApplies || item.quantity;
24
+ const maxApplies = modifierActions.getMaxItemUse(modifier) || 0;
25
+ const maxQuantity =
26
+ utils.math.mul(item.quantity || 0, maxApplies) || item.quantity;
26
27
 
27
28
  if (count < maxQuantity) {
28
29
  modifierCounts[modifier.modifierId] = count + 1;
@@ -0,0 +1,18 @@
1
+ module.exports = ({ actions, modifierActions }) =>
2
+ function splitAndCalculate({ parentItem, subItems }) {
3
+ if (!parentItem || !Array.isArray(subItems)) return [];
4
+ return subItems.map(each => {
5
+ const subTotal = actions.getSubtotal(actions.calculate(each));
6
+ const parentSubTotal = actions.getSubtotal(parentItem);
7
+
8
+ const newItem = {
9
+ ...each,
10
+ modifiers: modifierActions.getSplittedModifiers(
11
+ parentItem.modifiers,
12
+ parentSubTotal,
13
+ subTotal
14
+ ),
15
+ };
16
+ return actions.calculate(newItem);
17
+ });
18
+ };
@@ -0,0 +1,21 @@
1
+ module.exports = ({ actions }) =>
2
+ function spreadModifiers({ parentItem, subItems }) {
3
+ let subItemsWithCalculatedModifiers = actions.splitAndCalculate({
4
+ parentItem,
5
+ subItems,
6
+ });
7
+
8
+ // Validation
9
+
10
+ subItemsWithCalculatedModifiers = actions.validateFixedModifiersTotal({
11
+ parentItem,
12
+ subItems: [...subItemsWithCalculatedModifiers],
13
+ });
14
+
15
+ subItemsWithCalculatedModifiers = actions.validateCreditModifiersTotal({
16
+ parentItem,
17
+ subItems: [...subItemsWithCalculatedModifiers],
18
+ });
19
+
20
+ return subItemsWithCalculatedModifiers;
21
+ };
@@ -0,0 +1,23 @@
1
+ module.exports = ({ utils, actions, modifierActions }) => {
2
+ const { math } = utils;
3
+
4
+ return function validateCreditModifiersTotal({ parentItem, subItems }) {
5
+ const creditModifiersTotalAmount = modifierActions.getCreditModifiersTotal(
6
+ parentItem.modifiers
7
+ );
8
+ const subItemsCreditModifiersTotalAmount =
9
+ modifierActions.getCreditModifiersTotalEntities(subItems);
10
+
11
+ if (creditModifiersTotalAmount !== subItemsCreditModifiersTotalAmount) {
12
+ return actions.adjustCreditModifiersDifference({
13
+ subItems: [...subItems],
14
+ difference: math.sub(
15
+ creditModifiersTotalAmount,
16
+ subItemsCreditModifiersTotalAmount
17
+ ),
18
+ });
19
+ }
20
+
21
+ return subItems;
22
+ };
23
+ };
@@ -0,0 +1,23 @@
1
+ module.exports = ({ utils, actions, modifierActions }) => {
2
+ const { math } = utils;
3
+
4
+ return function validateFixedModifiersTotal({ parentItem, subItems }) {
5
+ const fixedModifiersTotalAmount = modifierActions.getFixedModifiersTotal(
6
+ parentItem.modifiers
7
+ );
8
+ const subItemsFixedModifiersTotalAmount =
9
+ modifierActions.getFixedModifiersTotalEntities(subItems);
10
+
11
+ if (fixedModifiersTotalAmount !== subItemsFixedModifiersTotalAmount) {
12
+ return actions.adjustFixedModifiersDifference({
13
+ subItems: [...subItems],
14
+ difference: math.sub(
15
+ fixedModifiersTotalAmount,
16
+ subItemsFixedModifiersTotalAmount
17
+ ),
18
+ });
19
+ }
20
+
21
+ return subItems;
22
+ };
23
+ };
@@ -32,29 +32,33 @@ module.exports = ({ actions, utils }) => {
32
32
  }
33
33
  });
34
34
 
35
- const itemIndexInSorted = matchingItems.findIndex(
35
+ let totalItemsLength = 0;
36
+
37
+ matchingItems.forEach(matchItem => {
38
+ totalItemsLength += matchItem.quantity || 0;
39
+ });
40
+
41
+ const itemIndex = matchingItems.findIndex(
36
42
  entry => entry._id === item._id
37
43
  );
38
44
 
39
- const itemSet =
40
- itemIndexInSorted >= 0 ? itemIndexInSorted + 1 : null;
41
-
42
- const matchingItemsLength = matchingItems.length;
45
+ const itemSetIndex = itemIndex >= 0 ? itemIndex + 1 : null;
43
46
 
44
47
  if (
45
48
  condition.operand === '$eq' &&
46
49
  conditionValue &&
47
- matchingItemsLength >= conditionValue
50
+ totalItemsLength >= conditionValue
48
51
  ) {
49
52
  const result = Math.floor(
50
- utils.math.div(matchingItemsLength, conditionValue)
53
+ utils.math.div(totalItemsLength, conditionValue)
51
54
  );
52
- if (itemSet <= result) {
55
+
56
+ if (itemSetIndex <= result) {
53
57
  return true;
54
58
  }
55
59
  }
56
60
  return actions.validateItemNumber(
57
- itemSet,
61
+ itemSetIndex,
58
62
  conditionValue,
59
63
  condition.operand
60
64
  );
@@ -101,7 +105,6 @@ module.exports = ({ actions, utils }) => {
101
105
  startRequestDate = null,
102
106
  allItems = null,
103
107
  } = opts;
104
- // const recommendedEndDate = storeActions.getRecommendedEndDate();
105
108
  return (
106
109
  modifier &&
107
110
  modifierConditionPass(modifier, {
@@ -0,0 +1,12 @@
1
+ module.exports = ({ utils, actions }) => {
2
+ const { math } = utils;
3
+
4
+ return function getCreditModifiersTotalEntities(entities) {
5
+ if (!Array.isArray(entities)) return 0;
6
+ return entities.reduce(
7
+ (acc, subEntity) =>
8
+ math.add(acc, actions.getCreditModifiersTotal(subEntity.modifiers)),
9
+ 0
10
+ );
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ module.exports = ({ utils, actions }) => {
2
+ const { math } = utils;
3
+
4
+ return function getFixedModifiersTotalEntities(entities) {
5
+ if (!Array.isArray(entities)) return 0;
6
+ return entities.reduce(
7
+ (acc, subEntity) =>
8
+ math.add(acc, actions.getFixedModifiersTotal(subEntity.modifiers)),
9
+ 0
10
+ );
11
+ };
12
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getMaxItemQuantity(modifier) {
3
+ if (!actions.isLimits(modifier)) return 0;
4
+ return modifier.properties.limits.maxItemQuantity;
5
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getMaxItemUse(modifier) {
3
+ if (!actions.isLimits(modifier)) return 0;
4
+ return modifier.properties.limits.maxItemUse;
5
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = ({ actions }) =>
2
+ function getMaxOrderUse(modifier) {
3
+ if (!actions.isLimits(modifier)) return 0;
4
+ return modifier.properties.limits.maxOrderUse;
5
+ };