public function afterSave() { Yii::app()->cache->delete(Yii::app()->currency->cacheKey); if ($this->default) { StoreCurrency::model()->updateAll(array('default' => 0), 'id != :id', array(':id' => $this->id)); } if ($this->main) { StoreCurrency::model()->updateAll(array('main' => 0), 'id != :id', array(':id' => $this->id)); } parent::afterSave(); }
/** * Delete currency * @param array $id */ public function actionDelete($id = array()) { if (Yii::app()->request->isPostRequest) { $model = StoreCurrency::model()->findAllByPk($_REQUEST['id']); if (!empty($model)) { foreach ($model as $m) { if ($m->main) { throw new CHttpException(404, Yii::t('StoreModule.admin', 'Ошибка. Удаление главной валюты запрещено.')); } if ($m->default) { throw new CHttpException(404, Yii::t('StoreModule.admin', 'Ошибка. Удаление валюты по умолчанию запрещено.')); } $m->delete(); } } if (!Yii::app()->request->isAjaxRequest) { $this->redirect('index'); } } }
<?php /** * Delivery method form */ return array('id' => 'deliveryUpdateForm', 'elements' => array('tab1' => array('type' => 'form', 'title' => '', 'elements' => array('name' => array('type' => 'text'), 'active' => array('type' => 'dropdownlist', 'items' => array(1 => Yii::t('StoreModule.admin', 'Да'), 0 => Yii::t('StoreModule.admin', 'Нет'))), 'description' => array('type' => 'SRichTextarea'), 'currency_id' => array('type' => 'dropdownlist', 'items' => CHtml::listData(StoreCurrency::model()->findAll(), 'id', 'name')), 'payment_system' => array('type' => 'dropdownlist', 'empty' => '---', 'items' => $this->model->getPaymentSystemsArray(), 'rel' => $this->model->id), '<div id="payment_configuration"></div>', 'position' => array('type' => 'text', 'hint' => Yii::t('StoreModule.admin', 'Оставьте пустым для установки максимального значения'))))));
/** * @return array */ public function loadCurrencies() { $currencies = Yii::app()->cache->get($this->cacheKey); if (!$currencies) { $currencies = StoreCurrency::model()->findAll(); Yii::app()->cache->set($this->cacheKey, $currencies); } return $currencies; }