Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: extends WellCommerce\Bundle\CoreBundle\Entity\TranslatableInterface, extends WellCommerce\Bundle\CoreBundle\Entity\TimestampableInterface, extends WellCommerce\Bundle\CoreBundle\Entity\BlameableInterface
 /**
  * Checks whether the coupon is not expired
  *
  * @param CouponInterface $coupon
  *
  * @return bool
  */
 private function isNotExpired(CouponInterface $coupon) : bool
 {
     $now = new \DateTime();
     $couponEndDate = $coupon->getValidTo();
     if ($couponEndDate instanceof \DateTime) {
         return $now <= $couponEndDate;
     }
     return true;
 }
 private function calculateCouponModifier(CouponInterface $coupon, OrderInterface $order) : float
 {
     $modifierType = $coupon->getModifierType();
     $modifierValue = $coupon->getModifierValue();
     $baseCurrency = $coupon->getCurrency();
     $targetCurrency = $order->getCurrency();
     $totalGrossPrice = $order->getProductTotal()->getGrossPrice();
     if ('%' === $modifierType) {
         return $modifierValue / 100;
     }
     if ('-' === $modifierType) {
         $modifierValue = $this->currencyHelper->convert($modifierValue, $baseCurrency, $targetCurrency);
         return $modifierValue >= $totalGrossPrice ? 1 : $modifierValue / $totalGrossPrice;
     }
     return 1;
 }
 /**
  * Calculates the modifier's value according to current currency and coupon's modifier
  *
  * @param CouponInterface $coupon
  * @param float|int       $amount
  * @param string          $targetCurrency
  *
  * @return float|int
  */
 protected function calculateModifierValue(CouponInterface $coupon, $amount, $targetCurrency)
 {
     $modifierType = $coupon->getModifierType();
     $modifierValue = $coupon->getModifierValue();
     $baseCurrency = $coupon->getCurrency();
     switch ($modifierType) {
         case '-':
             $modifierValue = $this->currencyHelper->convert($modifierValue, $baseCurrency, $targetCurrency);
             $modifier = $modifierValue >= $amount ? 1 : $modifierValue / $amount;
             break;
         case '%':
             $modifier = $modifierValue / 100;
             break;
         default:
             $modifier = 0;
     }
     return $modifier;
 }
Example #4
0
 /**
  * Checks whether the coupon is not expired
  *
  * @return bool
  */
 protected function isNotExpired()
 {
     $now = new \DateTime();
     $couponEndDate = $this->coupon->getValidTo();
     if ($couponEndDate instanceof \DateTime) {
         return $now <= $couponEndDate;
     }
     return true;
 }