/** * Always applied to the product total. */ public function perform(PromotionSubjectInterface $subject) { if ($this->isValid()) { $rate = $this->percentage / 100; $subject->addOrderDiscount($subject->getProductTotal() * $rate); } }
public function perform(PromotionSubjectInterface $subject) { if ($this->isValid()) { $discountedTotal = $subject->getOrderTotal() - $this->amount; if ($discountedTotal < 0) { // Modify amount to make the order total non-negative and stop at 0. $this->amount -= abs($discountedTotal); } $subject->addOrderDiscount($this->amount); } }