Exemple #1
0
 public function actionIndex()
 {
     $subcats = array();
     $categories = Productcategories::find()->where('ParentProductCategoryId= 0')->asArray()->all();
     foreach ($categories as $row) {
         $sub = Productcategories::find()->where('ParentProductCategoryId = ' . $row['ProductCategoryId'])->asArray()->all();
         array_push($subcats, $sub);
     }
     $featuredProducts = Products::find()->with('productmedias')->where('IsFeatured = 1')->asArray()->all();
     return $this->render('index', ['categories' => $categories, 'subcats' => $subcats, 'featuredProducts' => $featuredProducts]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Productcategories::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['ProductCategoryId' => $this->ProductCategoryId, 'ParentProductCategoryId' => $this->ParentProductCategoryId, 'created_by' => $this->created_by, 'LastUpdatedBy' => $this->LastUpdatedBy, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at]);
     $query->andFilterWhere(['like', 'Name', $this->Name])->andFilterWhere(['like', 'Description', $this->Description])->andFilterWhere(['like', 'ShortDescription', $this->ShortDescription])->andFilterWhere(['like', 'HtmlDecription', $this->HtmlDecription])->andFilterWhere(['like', 'AvatarUrl', $this->AvatarUrl])->andFilterWhere(['like', 'IconUrl', $this->IconUrl])->andFilterWhere(['like', 'Comment', $this->Comment]);
     return $dataProvider;
 }
Exemple #3
0
 public function actionIndex($id = null)
 {
     $sidebarcategories = Productcategories::find()->where('ParentProductCategoryId = 0')->asArray()->all();
     if ($id === 0 || $id == null) {
         $query = Products::find()->with('productmedias');
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 3]);
         $products = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
         $countProducts = Products::find()->count();
         $pagetitle = ['Name' => 'All products'];
     } else {
         $query = Products::find()->with('productmedias')->where('ProductCategoryId = ' . $id);
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 3]);
         $products = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
         $countProducts = Products::find()->where('ProductCategoryId = ' . $id)->count();
         $pagetitle = Productcategories::find()->where('ProductCategoryId = ' . $id)->asArray()->one();
     }
     return $this->render('index', ['sidebarcategories' => $sidebarcategories, 'products' => $products, 'pages' => $pages, 'countProducts' => $countProducts, 'pagetitle' => $pagetitle]);
 }
Exemple #4
0
<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use common\models\Suppliers;
use common\models\Brands;
use common\models\Producttypes;
use common\models\Productcategories;
/* @var $this yii\web\View */
/* @var $model common\models\Products */
/* @var $form yii\bootstrap\ActiveForm */
$dataProductCategory = ArrayHelper::map(Productcategories::find()->asArray()->all(), 'ProductCategoryId', 'Name');
$dataSuppliers = ArrayHelper::map(Suppliers::find()->asArray()->all(), 'SupplierId', 'Name');
$dataBrands = ArrayHelper::map(Brands::find()->asArray()->all(), 'BrandId', 'Name');
$dataProducttypes = ArrayHelper::map(Producttypes::find()->asArray()->all(), 'ProducttypeId', 'Name');
?>
<div class="products-form">

    <?php 
$form = ActiveForm::begin(['layout' => 'horizontal']);
?>

    <?php 
echo $form->field($model, 'Name', ['horizontalCssClasses' => ['wrapper' => 'col-sm-4']])->textInput(['maxlength' => 500]);
?>

    <?php 
echo $form->field($model, 'ProductCategoryId', ['horizontalCssClasses' => ['wrapper' => 'col-sm-3']])->dropDownList($dataProductCategory, ['prompt' => '----------Choose a Category----------']);
?>

    <?php