public function actionCreate()
 {
     $model = new PriceType();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
0
 public function actionCreate()
 {
     $lang = $this->getDefaultLanguage();
     $model = $this->module->getService('product');
     $model->language = $lang->language_id;
     $priceModel = $this->module->getService('price');
     $priceTypes = PriceType::find()->orderBy('sort DESC')->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($prices = yii::$app->request->post('Price')) {
             foreach ($prices as $typeId => $price) {
                 $type = PriceType::findOne($typeId);
                 $price = new $priceModel($price);
                 $price->type_id = $typeId;
                 $price->name = $type->name;
                 $price->sort = $type->sort;
                 $price->product_id = $model->id;
                 $price->save();
             }
         }
         $module = $this->module;
         $productEvent = new ProductEvent(['model' => $model]);
         $this->module->trigger($module::EVENT_PRODUCT_CREATE, $productEvent);
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'priceModel' => $priceModel, 'priceTypes' => $priceTypes]);
     }
 }
Exemple #3
0
 public function search($params)
 {
     $query = PriceType::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }