2

我尝试将 MaxBudget 功能添加到 Shopware 6 促销活动中。该字段应该像字段 Max total uses (MaxRedemptionsGlobal) 和 Max uses per customer (MaxRedemptionsPerCustomer) 一样工作。

这意味着,如果促销的预算为... 1000 欧元,则当所有订单的促销折扣加起来达到 1000 欧元时,促销无效。就像达到最大总使用量阈值一样。

我将 MaxBudget 添加为实体扩展,并在 Max 下有一个字段。每个客户在管理中的使用。

至于店面购物车,我注意到 Max 使用的条件(全球和每个客户)并检查了 PromotionCollector。在private function getEligiblePromotionsWithDiscounts有此代码验证订单最大使用每个客户和订单最大使用全局:

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

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

我需要的是,在上述条件之后添加一个附加条件,如下所示:

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

所以问题是,除了这两个之外,我在哪里可以添加一个额外的条件来检查最大预算?我是否必须扩展 PromotionCollector 类并覆盖该方法?也许我可以添加一个像 PromotionMaxBudgetCollector 这样的新类。我不确定这是否是正确的方法。

4

1 回答 1

0

我认为您面临的问题\Shopware\Core\Checkout\Promotion\Cart\PromotionCollector::getEligiblePromotionsWithDiscounts是私有的,不能进行装饰以添加新条件。

如果您的条件不满足,您可以装饰 \Shopware\Core\Checkout\Promotion\PromotionEntity::hasDiscountor\Shopware\Core\Checkout\Promotion\PromotionEntity::isOrderCountValid并返回。false

于 2022-01-19T19:26:40.313 回答