Inheritance: extends CApplicationComponent
 public function testCodeNotFound()
 {
     $countBefore = Coupon::model()->count();
     $cm = new CouponManager();
     $this->assertFalse($cm->registerCoupon($_GET['non_existing_code']));
     $countAfter = Coupon::model()->count();
     $this->assertEquals($countBefore, $countAfter);
 }
Exemple #2
0
 /**
  * @throws CHttpException
  */
 public function actionClear()
 {
     if (!Yii::app()->getRequest()->getIsPostRequest()) {
         throw new CHttpException(404);
     }
     $this->couponManager->clear();
     Yii::app()->ajax->success(Yii::t("CouponModule.coupon", "Coupons are deleted"));
 }
Exemple #3
0
 /**
  * Saves the state of the object in the session.
  * @return void
  */
 protected function saveState()
 {
     Yii::app()->getUser()->setState($this->cartId, serialize($this->toArray()));
     $this->couponManager->check();
 }
Exemple #4
0
 /**
  * @throws CHttpException
  */
 public function actionClear()
 {
     $this->couponManager->clear();
     Yii::app()->ajax->success(Yii::t("CouponModule.coupon", "Coupons are deleted"));
 }
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $model = new Listing();
     $coupons = new CouponManager();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Listing'])) {
         $model->attributes = $_POST['Listing'];
         if (isset($_POST['Coupon'])) {
             $coupons->manage($_POST['Coupon']);
         }
         if (!Yii::app()->user->isSuperadmin()) {
             $model->wlabel_id = Yii::app()->user->getWhiteLabelId();
         }
         if (Yii::app()->user->isAdvertiser()) {
             $model->advertiser_id = Yii::app()->user->getAdvertiserId();
         }
         $model->date_created = date("Y-m-d h:i:s");
         $transaction = Yii::app()->db->beginTransaction();
         $saveError = false;
         $logoFile = CUploadedFile::getInstance($model, 'logo');
         if ($logoFile != null) {
             $newFileName = uniqid(rand()) . '.' . Utils::getFileExtension($logoFile->name);
             $model->logo = $newFileName;
         }
         $valid = $model->validate();
         if (isset($_POST['Coupon'])) {
             $valid = $coupons->validate($model) && $valid;
         }
         if ($valid) {
             if ($model->save()) {
                 if (!$this->saveCategoriesToListing($model)) {
                     $saveError = true;
                 }
                 if (!$this->saveLocationsToListing($model)) {
                     $saveError = true;
                 }
                 if ($logoFile != null) {
                     $logoFile->saveAs(Yii::app()->user->getFullPathToImages(Yii::app()->params['listingLogo']) . $newFileName);
                 }
                 if (isset($_POST['Coupon'])) {
                     if (!$coupons->save($model)) {
                         $saveError = true;
                     }
                 }
             } else {
                 $saveError = true;
             }
             if ($saveError) {
                 $transaction->rollBack();
             } else {
                 $transaction->commit();
                 $this->redirect(array('index'));
             }
         }
     }
     if (isset($_GET['Listing'])) {
         $model->attributes = $_GET['Listing'];
     }
     $this->render('index', array('model' => $model, 'coupons' => $coupons));
 }