商店软件6-在最大总使用量和每个客户的最大使用量旁边添加新的促销无效条件



我试图为Shopware 6促销活动添加MaxBudget功能。该字段的工作原理应类似于字段Max total uses(MaxRedemptionsGlobal(和Max uses per customer(MaxRedumptionsPerCustomer(。

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

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

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

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

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

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

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

我认为您面临的问题是ShopwareCoreCheckoutPromotionCartPromotionCollector::getEligiblePromotionsWithDiscounts是私有的,无法进行装饰以添加新条件。

如果您的条件不满足,您可以装饰ShopwareCoreCheckoutPromotionPromotionEntity::hasDiscountShopwareCoreCheckoutPromotionPromotionEntity::isOrderCountValid并返回false

最新更新