/**
  * 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);
     }
 }
Example #3
0
 /**
  * If no date range is set, the promotion is considered to be active.
  *
  * @return boolean
  */
 public function isActive(PromotionSubjectInterface $subject)
 {
     $currentDate = $subject->getCurrentDateTime();
     $startDate = $this->start ? $subject->getDateTime($this->start) : null;
     $endDate = $this->end ? $subject->getDateTime($this->end) : null;
     if ($this->start && $this->end) {
         return $currentDate > $startDate && $currentDate < $endDate;
     }
     if ($this->start) {
         return $currentDate > $startDate;
     }
     if ($this->end) {
         return $currentDate < $endDate;
     }
     return true;
 }
Example #4
0
 public function getValidationResult(PromotionSubjectInterface $subject)
 {
     return version_compare($subject->getOrderTotal(), $this->value, $this->operator);
 }
 public function getValidationResult(PromotionSubjectInterface $subject)
 {
     return $this->operator && $subject->isFirstTimeCustomer();
 }
Example #6
0
 /**
  * If the code has a null usage limit it is considered to have unlimited usage.
  *
  * @return boolean
  */
 public function isActive(PromotionSubjectInterface $subject)
 {
     return $subject->getPromotionCode() == $this->code && ($this->usageLimitPerCode ? $subject->getPromotionUsageCount() < $this->usageLimitPerCode : true) && ($this->usageLimitPerUser ? $subject->getPromotionUserCount() < $this->usageLimitPerUser : true);
 }
Example #7
0
 public function perform(PromotionSubjectInterface $subject)
 {
     $subject->setFreeShipping();
 }