예제 #1
0
 public function actionUpdate()
 {
     $this->htmlOption = array('class' => 'icon-head head-products', 'header' => "编辑优惠券", 'button' => array(array('class' => 'scalable save', 'id' => 'form-save', 'header' => '保存')));
     $model = $this->loadModel();
     if ($model->discount_customer_ID !== 0) {
         $model->discount_customer_email = customer_entity::model()->findByPk($model->discount_customer_ID)->customer_email;
     }
     if ($_POST['discount']) {
         $model->attributes = $_POST['discount'];
         $model->discount_customer_email = $_POST['discount']['discount_customer_email'];
         if ($customer = customer_entity::model()->findByAttributes(array('customer_email' => $model->discount_customer_email))) {
             $model->discount_customer_ID = $customer->customer_ID;
         } else {
             $model->discount_customer_ID = 0;
         }
         if ($model->save()) {
             discount_category::updateItem($model->discount_ID, $_POST['discount']['discount_category_ID']);
             $this->redirect(array('index'));
         }
         $tree = $this->constructCategoryTree($_POST['discount']['discount_category_ID']);
     }
     if (!isset($tree)) {
         $tree = $this->constructCategoryTree(discount_category::items($model->discount_ID));
     }
     $this->constructScript('update');
     $this->render('update', array('model' => $model, 'tree' => $tree));
 }
예제 #2
0
파일: cart.php 프로젝트: htom78/XZB2c
 public function validateDiscount($orderTotal, $discountID, $checkCartDiscount = false)
 {
     $discount = discount_entity::model()->findByPk($discountID);
     if (!$orderTotal > 0) {
         return 'cannot add voucher if order is free';
     }
     if (!$discount->discount_active == 1) {
         return 'this voucher has already been used or is disabled';
     }
     if (!$discount->discount_quantity) {
         return 'this voucher has expired (usage limit attained)';
     }
     if ($checkCartDiscount and ($this->nbDiscounts($discount->discount_ID) >= $discount->discount_quantity_per_user or order_discount::nbDiscountCustomer(Yii::app()->user->getId(), $discount->discount_ID) + $this->nbDiscounts($discount->discount_ID) >= $discount->discount_quantity_per_user)) {
         return 'you cannot use this voucher anymore (usage limit attained)';
     }
     if (strtotime($discount->discount_from) > time()) {
         return 'this voucher is not yet valid';
     }
     if (strtotime($discount->discount_to) < time()) {
         return 'this voucher has expired';
     }
     if (sizeof($discounts = cart_discount::items($this->cart_ID)) >= 1 and $checkCartDiscount) {
         if (!$discount->discount_cumulable == 1) {
             return 'this voucher isn\'t cumulative with other current discounts';
         }
         foreach ($discounts as $row) {
             if (!$row['discount_cumulable'] == 1) {
                 return 'previous voucher added isn\'t cumulative with other discounts';
             }
         }
     }
     if (is_array($discounts) and array_key_exists($discount->discount_ID, $discounts)) {
         return 'this voucher is already in your cart';
     }
     if ($discount->discount_customer_ID and $discount->discount_customer_ID != Yii::app()->user->getId()) {
         if (!Yii::app()->user->isGuest) {
             return 'you cannot use this voucher-try to log in if you own it';
         }
         return 'you cannot use this voucher';
     }
     $onlyProductWithDiscount = true;
     if (!$discount->discount_cumulable_reduction == 1) {
         foreach ($this->products as $product) {
             if (!intval($product['product_reducetion_price']) and !intval($product['product_reducetion_percent'])) {
                 $onlyProductWithDiscount = false;
             }
         }
     }
     if (!$discount->discount_cumulable_reduction == 1 and $onlyProductWithDiscount) {
         return 'this voucher isn\'t cumulative on products with reduction';
     }
     $categories = discount_category::items($discount->discount_ID);
     $returnErrorNoProductCategory = true;
     foreach ($this->products as $product) {
         if (count($categories)) {
             if ($product->productInCategories($categories)) {
                 $returnErrorNoProductCategory = false;
             }
         }
     }
     if ($returnErrorNoProductCategory) {
         return 'this discount isn\'t applicable to that product category';
     }
     $minimal = product_entity::decoratePrice($discount->discount_minimal);
     if ($orderTotal < $minimal) {
         return 'the total amount of your order isn\'t high enough or this voucher cannot be used with those products';
     }
     return false;
 }
예제 #3
0
 protected function beforeDelete()
 {
     discount_category::deleteItem($this->discount_ID, discount_category::items($this->discount_ID));
     if ($this->hasEventHandler('onBeforeDelete')) {
         $event = new CModelEvent($this);
         $this->onBeforeDelete($event);
         return $event->isValid;
     } else {
         return true;
     }
 }