Beispiel #1
0
 public static function update_product_category_rel($model)
 {
     ProductCategoryRel::deleteAll(['product_id' => $model->product_id]);
     foreach ($model->category_id as $key => $value) {
         $new_model = new ProductCategoryRel();
         $new_model->product_id = $model->product_id;
         $new_model->category_id = $value;
         if ($new_model->save()) {
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return true;
 }
 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);
     }
 }
 /**
  * Deletes an existing Product model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     ProductCategoryRel::deleteAll(['product_id' => $id]);
     $images = ProductImageRel::findAll(['product_id' => $id]);
     if (!empty($images)) {
         foreach ($images as $key => $value) {
             unlink(\Yii::getAlias('@webroot') . '/product_uploads/' . $value->image);
         }
     }
     ProductImageRel::deleteAll(['product_id' => $id]);
     $files = ProductFiles::findAll(['product_id' => $id]);
     if (!empty($files)) {
         foreach ($files as $key => $value) {
             unlink(\Yii::getAlias('@webroot') . '/product_files/' . $value->file_name);
         }
     }
     ProductFiles::deleteAll(['product_id' => $id]);
     ProductSpecification::deleteAll(['product_id' => $id]);
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }