/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'depth' => $this->depth, 'lft' => $this->lft, 'rgt' => $this->rgt, 'root' => $this->root]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(Category::className(), ['id' => 'category_id']); }
/** * Display products by category * - Product catalog as a grid * @param string $category_id */ public function actionCatalog($category_id = null) { $catalog = Category::findOne($category_id); $this->render('catalog', ['catalog' => $catalog]); }
</div> </div> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'imageFile')->widget(FileInput::className()); ?> <?php echo $form->field($model, 'parent', ['addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-heart"></i>']]])->widget(Select2::className(), ['data' => [null => Yii::t('shop', '-- Select parent Category --')] + Category::CategoryOptions()]); ?> </div> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('shop', 'Create') : Yii::t('shop', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();
?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'price')->textInput(); ?> <?php echo $form->field($model, 'image')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'category_id')->widget(Select2::className(), ['data' => [null => Yii::t('shop', '-- Select Associated Category --')] + Category::CategoryOptions()]); ?> <?php /* @FIXME: The Associated Shop related to this product will be calculate based on selected category above.... = $form->field($model, 'shop_name')->widget(Select2::className(), [ 'data' => [null => Yii::t('shop', '-- Select Associated Shop --')] + ArrayHelper::map(Shop::find()->all(), 'name', 'name'), ])*/ ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('shop', 'Create') : Yii::t('shop', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>