コード例 #1
0
ファイル: Cart.php プロジェクト: jigoshop/Jigoshop2
 /**
  * @param $coupon Coupon
  */
 public function addCoupon($coupon)
 {
     if (!is_object($coupon)) {
         parent::addCoupon($coupon);
         return;
     }
     if (isset($this->couponData[$coupon->getId()])) {
         return;
     }
     if (is_numeric($coupon->getOrderTotalMinimum()) && $this->getTotal() < $coupon->getOrderTotalMinimum()) {
         throw new Exception(sprintf(__('Cannot apply coupon "%s". Order total less than %s.'), $coupon->getCode(), ProductHelper::formatPrice($coupon->getOrderTotalMinimum())));
     }
     if (is_numeric($coupon->getOrderTotalMaximum()) && $this->getTotal() > $coupon->getOrderTotalMaximum()) {
         throw new Exception(sprintf(__('Cannot apply coupon "%s". Order total more than %s.'), $coupon->getCode(), ProductHelper::formatPrice($coupon->getOrderTotalMaximum())));
     }
     if ($coupon->isIndividualUse()) {
         $this->removeAllCouponsExcept(array());
     }
     $discount = $coupon->getDiscount($this);
     $this->couponData[$coupon->getId()] = array('object' => $coupon, 'discount' => $discount);
     parent::addCoupon($coupon->getCode());
     $this->addDiscount($discount);
 }