public function actionProduct_view()
 {
     if (Yii::$app->request->isAjax) {
         $this->layout = 'blank';
         $id = $_POST['id'];
         $model = ProductCategory::find()->where(['id' => $id])->one();
         $data = ProductCategoryRel::find()->where(['category_id' => $id])->orderBy('sort_order', 'DESC')->all();
         $response['upload_view'] = \yii\base\Controller::renderPartial('product_list_product_view', ['model' => $model, 'data' => $data]);
         $response['Category_name'] = $model->cat_title;
         return json_encode($response);
     }
 }
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model_q = new ProductSpecification();
     $query = ProductSpecification::find()->indexBy('id');
     // where `id` is your primary key
     $query->andWhere(['=', 'product_id', $id]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $models = $dataProvider->getModels();
     if (Yii::$app->request->isAjax) {
         if (isset($_POST['ProductSpecification']) && isset($_POST['ProductSpecification']['cat_create'])) {
             $model_q = new ProductSpecification();
             $model_q->attributes = $_POST['ProductSpecification'];
             if ($model_q->save()) {
                 $response['files'] = ['ok'];
                 $response['result'] = 'success';
                 $model_uu = new ProductSpecification();
                 $query = ProductSpecification::find()->indexBy('id');
                 // where `id` is your primary key
                 $query->andWhere(['=', 'product_id', $id]);
                 $dataProvider = new ActiveDataProvider(['query' => $query]);
                 $models = $dataProvider->getModels();
                 $product_specifications = ProductSpecification::find()->where(['product_id' => $id])->all();
                 $response['preview_cont'] = $this->renderAjax('specification_preview', ['data' => $product_specifications]);
                 $response['specification_list'] = $this->renderAjax('ajax_cont', ['dataProvider' => $dataProvider, 'model_q' => $model_uu]);
                 return json_encode($response);
             } else {
                 var_dump($_POST['ProductSpecification']);
                 $response['result'] = 'error';
                 $response['files'] = Html::errorSummary($model_q);
                 return json_encode($response);
             }
         } else {
             if (ProductSpecification::loadMultiple($models, Yii::$app->request->post()) && ProductSpecification::validateMultiple($models)) {
                 $count = 0;
                 foreach ($models as $index => $model_q) {
                     // populate and save records for each model
                     if ($model_q->save()) {
                         $count++;
                     }
                 }
                 Yii::$app->session->setFlash('success', "Processed {$count} records successfully.");
                 $response['files'] = "Processed {$count} records successfully.";
                 $response['result'] = 'success';
                 return json_encode($response);
             } else {
                 if (isset($_POST['is_banner'])) {
                     $model_uu = new ProductSpecification();
                     $query = ProductSpecification::find()->indexBy('id');
                     // where `id` is your primary key
                     $query->andWhere(['=', 'product_id', $id]);
                     $dataProvider = new ActiveDataProvider(['query' => $query]);
                     $models = $dataProvider->getModels();
                     $product_specifications = ProductSpecification::find()->where(['product_id' => $id])->all();
                     $response['preview_cont'] = $this->renderAjax('specification_preview', ['data' => $product_specifications]);
                     $response['specification_list'] = $this->renderAjax('ajax_cont', ['dataProvider' => $dataProvider, 'model_q' => $model_uu]);
                     return json_encode($response);
                 }
             }
         }
     }
     $model = $this->findModel($id);
     $ProductCategoryRel_model_q = ProductCategoryRel::find()->where(['product_id' => $id])->all();
     $ProductImageRel = new ProductImageRel();
     if (empty($ProductCategoryRel_model_q)) {
         $ProductCategoryRel = new ProductCategoryRel();
     } else {
         $ProductCategoryRel = new ProductCategoryRel();
         $ProductCategoryRel->category_id = ArrayHelper::getColumn($ProductCategoryRel_model_q, 'category_id');
     }
     if ($model->load(Yii::$app->request->post()) && $ProductCategoryRel->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $ProductCategoryRel->product_id = $model->id;
             if (empty($ProductCategoryRel->category_id)) {
                 ProductCategoryRel::deleteAll(['product_id' => $ProductCategoryRel->product_id]);
                 $ProductCategoryRel->category_id = 0;
                 $ProductCategoryRel->save();
             } else {
                 Product::update_product_category_rel($ProductCategoryRel);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             var_dump($model->getErrors());
         }
     } else {
         return $this->render('update', ['model' => $model, 'ProductCategoryRel' => $ProductCategoryRel, 'ProductImageRel' => $ProductImageRel, 'dataProvider' => $dataProvider, 'model_q' => $model_q]);
     }
 }