/** * Updates an existing ProductCategory 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); $parentCategories = ProductCategory::find()->where(['product_category_parent_id' => ''])->andWhere(['NOT', 'product_category_id', $model->product_category_id])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => (string) $model->_id]); } else { return $this->render('update', ['model' => $model, 'parentCategories' => $parentCategories]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'lvl' => $this->lvl, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * Displays homepage. * * @return mixed */ public function actionIndex() { $allCategories = ProductCategory::find()->with('products')->all(); $allProducts = Product::find()->all(); $recProducts = array(); for ($i = 0; $i < 3; $i++) { $currRand = rand(0, count($allProducts) - 1); $recProducts[] = $allProducts[$currRand]; } return $this->render('index', ['allCats' => $allCategories, 'recProducts' => $recProducts]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'product_category_id', $this->product_category_id])->andFilterWhere(['like', 'product_category_parent_id', $this->product_category_parent_id])->andFilterWhere(['like', 'product_category_name', $this->product_category_name])->andFilterWhere(['like', 'product_category_tag', $this->product_category_tag])->andFilterWhere(['like', 'product_category_keywords', $this->product_category_keywords])->andFilterWhere(['like', 'product_category_icon', $this->product_category_icon])->andFilterWhere(['like', 'product_category_icon_mobile', $this->product_category_icon_mobile])->andFilterWhere(['like', 'product_category_create_date', $this->product_category_create_date])->andFilterWhere(['like', 'product_category_create_user_id', $this->product_category_create_user_id])->andFilterWhere(['like', 'product_category_last_update_date', $this->product_category_last_update_date])->andFilterWhere(['like', 'product_category_last_update_user_id', $this->product_category_last_update_user_id])->andFilterWhere(['like', 'product_category_status', $this->product_category_status])->andFilterWhere(['like', 'merchant_brand_fk', $this->merchant_brand_fk]); return $dataProvider; }
/** * 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); $categoryModel = new ProductCategory(); $companyModel = new ProductCompany(); $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all()); $treeCompany = ArrayHelper::map($companyModel->findAll(['status' => 10]), 'id', 'title'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'treeParents' => $treeParents, 'treeCompany' => $treeCompany]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'lft' => $this->lft, 'rgt' => $this->rgt, 'depth' => $this->depth, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]); return $dataProvider; }
/** * Creates a new ProductCategory model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ProductCategory(); $treeParents = TreeHelper::build($model->find()->addOrderBy('tree')->addOrderBy('lft')->all()); if ($model->load(Yii::$app->request->post())) { if (empty($model->parent_id)) { $model->makeRoot(); } else { $root = $model->findOne(['id' => $model->parent_id]); $model->appendTo($root); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]); } }