Every
How bundles based on quantity multiples work
This alternative bundling strategy maximizes the number of items picked from the targeted group (listed according to the desired sorting logic) ensuring that it is equal to or a multiple of a specified number.
Bundles of type every
can be created only from one group containing at least one item. If the related actions.groups
array is made by more than one group, the Rule Engine will return an error. If the specified group is empty, the action won't be applied.
type
Must be "every"
.
sort
value
How the every
algorithm works
every
algorithm worksThe items of the targeted group are sorted according to the
sort.direction
function applied to thesort.attribute
numeric field.The total quantity of units within the group is calculated by adding up the quantities of each item:
Q = q1 + q2 + ... + qn
Being
M
the maximum multiple of the numberV
specified in the bundle'svalue
key that doesn't exceed the total quantityQ
, the number of units that won't be discountedX
is calculated by subtractingM
fromQ
:X = Q - M = Q mod V
Starting from the bottom of the ordered list generated by the sorting, a quantity of units equal to
X
is removed to get the final list of items that will be discounted.
If the number specified in the value
key is already a multiple of the total quantity (i.e. M = Q
and consequently X = 0
), the action will be applied to all the items of the group.
If some items of the group match the bundle's sort.direction
function with the same numeric value of the field specified in the sort.attribute
value, they will be sorted as they are listed in the payload against which the rule is evaluated.
Example
Let's assume that a rule's conditions define the discountable-items
group of line items as follows:
Let's consider the following action that applies a 10% discount to the group above. The discount will be applied to bundles built by picking the items 2 at a time and prioritizing the ones with higher unit amounts:
1. Sorting
The items of the group are sorted based on their unit amount, from the highest to the lowest:
3000
2000
1000
2. Total quantity of units
The total quantity of units within the group is Q = 2 + 3 + 2 = 7
.
3. Number of units to be removed
Being the number of the bundle.value
key 2
, the number of units to be removed is calculated as the remainder of the division between the total quantity and the value: 7 mod 2 = 1
.
4. Items to be discounted
One item will be removed starting from the bottom of the ordered list (i.e. one sticker), thus getting to the final outcome, resulting in a 10% discount applied to 2x bundles, not to the additional item with lower unit price:
5400
3600
1800
Last updated