Shopware 6 - add new Promotion invalidation condition next to Max total uses and Max uses per customer

Viewed 129

I try to add a MaxBudget functionality to the Shopware 6 promotions. This field is supposed to work like the fields Max total uses (MaxRedemptionsGlobal) and Max uses per customer (MaxRedemptionsPerCustomer).

This means that if the promotion has a budget of say... 1000 euros, when the discount from this promotion for all orders adds up to 1000 euros the promotion is invalid. Just like when Max total uses threshold is reached.

I added MaxBudget as an entity extension and have a field for it under Max. uses per customer in administration.

As for the storefront cart I noticed the conditions for Max uses (global and per customer) and checked in PromotionCollector. In the private function getEligiblePromotionsWithDiscounts there is this code validating the order max uses per customer and order max uses global:

if (!$promotion->isOrderCountValid()) {
    continue;
}

if ($customer !== null && !$promotion->isOrderCountPerCustomerCountValid($customer->getId())) {
    continue;
}

What I need is, right after the conditions above to add an additional condition like the following:

if ($promotion->getMaxBudget()->maxBudgetReached()) {
    continue;
}

So the question would be, where can I add an additional condition besides these two, to check the max budget ? Do I have to extend the PromotionCollector class and override the method ? Maybe I can add a new class like PromotionMaxBudgetCollector. I am not sure if this is the right approach.

1 Answers
Related