/** * 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; }
/** * 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; }