Ejemplo n.º 1
0
 /**
  * Check if a coupon can be currently used.
  *
  * @param CouponInterface $coupon
  *
  * @return bool
  */
 private function canBeUsed(CouponInterface $coupon)
 {
     $count = $coupon->getCount();
     if ($count === 0) {
         return true;
     }
     if ($coupon->getUsed() < $count) {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Checks whether a coupon can be applied or not.
  *
  * @param CouponInterface $coupon Coupon to work with
  * @param float           $price  Price
  *
  * @return boolean Coupon can be applied
  *
  * @throws CouponBelowMinimumPurchaseException
  * @throws CouponAppliedException
  * @throws CouponNotActiveException
  */
 protected function checkCoupon(CouponInterface $coupon, $price)
 {
     /**
      * check if coupon is enabled and not deleted
      */
     if (!$coupon->isEnabled()) {
         throw new CouponNotActiveException();
     }
     $now = new DateTime();
     /**
      * check if coupon is active
      */
     if ($coupon->getValidFrom() > $now || $coupon->getValidTo() < $now) {
         throw new CouponNotActiveException();
     }
     /**
      * check if coupon still can be applied
      */
     if ($coupon->getCount() - $coupon->getUsed() < 1) {
         throw new CouponAppliedException();
     }
     /**
      * you cannot add this coupon, too cheap
      */
     if ($coupon->getMinimumPurchase()->getAmount() > $price) {
         throw new CouponBelowMinimumPurchaseException();
     }
     return true;
 }