コード例 #1
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $product = new Products();
     $product_image = new ProductsImages();
     if ($product->load(Yii::$app->request->post()) && $product->load_images(Yii::$app->request->post()) && $product->load_parameters(Yii::$app->request->post('ParametersValues')) && $product->load_categories(Yii::$app->request->post('cat_tree')) && $product->load_prices(Yii::$app->request->post('Prices'))) {
         if ($product->validate()) {
             if ($product->save(false)) {
                 Yii::$app->session->setFlash('success', Yii::t('storecube', 'PRODUCT_CREATE_SUCCESS'));
                 return $this->redirect(['update', 'id' => $product->id]);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('storecube', 'PRODUCT_CREATE_FAIL'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             // TODO: доделать
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($product);
         }
     } else {
         return $this->render('create', ['product' => $product, 'product_image' => $product_image, 'statusArray' => Products::getStatusArray()]);
     }
 }