Пример #1
0
 public function actionUpdateOld($new = false)
 {
     if ($new === true) {
         $model = new ShopCurrency();
         $model->unsetAttributes();
     } else {
         $model = ShopCurrency::model()->findByPk($_GET['id']);
     }
     if (!$model) {
         throw new CHttpException(404, Yii::t('ShopModule.admin', 'NO_FOUND_CURRENCY'));
     }
     $form = new CMSForm($model->config, $model);
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['ShopCurrency'];
         if ($model->validate()) {
             $model->save();
             //
             $products = ShopProduct::model()->findAllByAttributes(array('currency_id' => $model->id));
             if (isset($products)) {
                 foreach ($products as $product) {
                     $convert = ShopProduct::model()->findByPk($product);
                     $convert->price = $convert->price * $model->rate / $model->rate_old;
                     $convert->save();
                 }
             }
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model, 'form' => $form));
 }