/** * 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 = $this->findModel($id); $modelProdMeta = ProductMeta::find()->where(['prod_id' => $id]); if ($model->load(Yii::$app->request->post()) && $model->save()) { $prod_id = $model->prod_id; $postData = Yii::$app->request->post(); foreach ($model->cat_id as $cat) { $catModel = new ProdCat(); $catModel->cat_id = $cat; $catModel->prod_id = $prod_id; $catModel->save(); } $file = UploadedFile::getInstances($model, 'images'); $model->file = $file[0]; $image_path = Yii::getAlias('@frontend') . '/web/uploads/product/' . $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension; $model->file->saveAs($image_path); $this->updateProductMeta($id, 'prod_img', $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension); foreach ($postData['PMeta'] as $key => $meta_value) { $this->updateProductMeta($id, $key, $meta_value); } return $this->redirect(['view', 'id' => $model->prod_id]); } else { return $this->render('update', ['model' => $model, 'modelProdMeta' => $modelProdMeta]); } }
/** * 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 = $this->findModel($id); $modelProdMeta = ProductMeta::find()->where(['prod_id' => $id]); $stores = []; if (\Yii::$app->user->identity->id == 1) { $stores = \common\models\UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all(); $stores = \yii\helpers\ArrayHelper::getColumn($stores, 'store_id'); $storeList = \common\models\Store::find()->where(['IN', 'store_id', $stores])->all(); } else { $storeList = \common\models\Store::find()->all(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { $prod_id = $model->prod_id; $postData = Yii::$app->request->post(); foreach ($model->cat_id as $cat) { $catModel = new ProdCat(); $catModel->cat_id = $cat; $catModel->prod_id = $prod_id; $catModel->save(); } $file = UploadedFile::getInstances($model, 'images'); $model->file = $file[0]; $image_path = Yii::getAlias('@frontend') . '/web/uploads/product/' . $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension; $model->file->saveAs($image_path); $this->updateProductMeta($id, 'prod_img', $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension); foreach ($postData['PMeta'] as $key => $meta_value) { $this->updateProductMeta($id, $key, $meta_value); } return $this->redirect(['view', 'id' => $model->prod_id]); } else { return $this->render('update', ['model' => $model, 'modelProdMeta' => $modelProdMeta, 'storeList' => $storeList]); } }