コード例 #1
0
ファイル: Order.php プロジェクト: syrexby/domovoishop.by
 /**
  * @param array $coupons
  * @return bool
  */
 public function applyCoupons(array $coupons)
 {
     if (!$this->isCouponsAvailable()) {
         return true;
     }
     $coupons = $this->getValidCoupons($coupons);
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         foreach ($coupons as $coupon) {
             $model = new OrderCoupon();
             $model->setAttributes(['order_id' => $this->id, 'coupon_id' => $coupon->id, 'create_time' => new CDbExpression('NOW()')]);
             $model->save();
             $coupon->decreaseQuantity();
         }
         $this->coupon_discount = $this->getCouponDiscount($coupons);
         $this->delivery_price = $this->getDeliveryCost();
         $this->update(['coupon_discount', 'delivery_price']);
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
 }
コード例 #2
0
ファイル: Order.php プロジェクト: RonLab1987/43berega
 public function applyCoupons(array $coupons)
 {
     if (!$this->isCouponsAvailable()) {
         return true;
     }
     $coupons = $this->getValidCoupons($coupons);
     foreach ($coupons as $coupon) {
         $model = new OrderCoupon();
         $model->setAttributes(['order_id' => $this->id, 'coupon_id' => $coupon->id, 'create_time' => new CDbExpression('NOW()')]);
         $model->save();
         if ($this->getIsNewRecord()) {
             $coupon->decreaseQuantity();
         }
     }
     $this->coupon_discount = $this->getCouponDiscount($coupons);
     $this->delivery_price = $this->getDeliveryCost();
     return true;
 }