Esempio n. 1
0
 /**
  * Update discount
  * @param bool $new
  * @throws CHttpException
  */
 public function actionUpdate($new = false)
 {
     if ($new === true) {
         $model = new ShopDiscount();
     } else {
         $model = ShopDiscount::model()->findByPk($_GET['id']);
     }
     if (!$model) {
         throw new CHttpException(404, Yii::t('DiscountsModule.admin', 'NO_FOUND_DISCOUNT'));
     }
     $this->pageName = $model->isNewRecord ? Yii::t('DiscountsModule.admin', 'Создание скидки') : Yii::t('DiscountsModule.admin', 'Редактирование скидки');
     $this->breadcrumbs = array(Yii::t('DiscountsModule.default', 'MODULE_NAME') => array('/admin/shop'), Yii::t('DiscountsModule.default', 'MODULE_NAME') => $this->createUrl('index'), $this->pageName);
     Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/default.update.js', CClientScript::POS_END);
     if (Yii::app()->request->isPostRequest) {
         if (!isset($_POST['ShopDiscount']['manufacturers'])) {
             $model->manufacturers = array();
         }
         if (!isset($_POST['ShopDiscount']['categories'])) {
             $model->categories = array();
         }
         if (!isset($_POST['ShopDiscount']['userRoles'])) {
             $model->userRoles = array();
         }
         $model->attributes = $_POST['ShopDiscount'];
     }
     $form = new TabForm($model->getForm(), $model);
     $form->additionalTabs[Yii::t('DiscountsModule.admin', 'Категории')] = array('content' => $this->renderPartial('_categories', array('model' => $model), true));
     if (Yii::app()->request->isPostRequest) {
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model, 'form' => $form));
 }
Esempio n. 2
0
 /**
  * Attach behavior to model
  * @param $owner
  */
 public function attach($owner)
 {
     if (!$owner->isNewRecord && Yii::app()->controller instanceof Controller) {
         if (DiscountBehavior::$discounts === null) {
             DiscountBehavior::$discounts = ShopDiscount::model()->activeOnly()->applyDate()->findAll();
         }
         parent::attach($owner);
     }
 }
Esempio n. 3
0
 public function afterUninstall()
 {
     $db = Yii::app()->db;
     $tablesArray = array(ShopDiscount::model()->tableName(), $db->tablePrefix . 'shop_discount_category', $db->tablePrefix . 'shop_discount_manufacturer');
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     GridColumns::model()->deleteAll("grid_id='shopdiscount-grid'");
     return parent::afterUninstall();
 }