/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     ProductCategory::truncate();
     //For each product we will be inserting random number of keywords
     foreach (range(1, 50) as $product_index) {
         $num_entries = rand(0, 3);
         foreach (range(0, $num_entries) as $entries) {
             ProductCategory::create(['product_id' => $product_index, 'category_id' => rand(1, 5)]);
         }
     }
 }
Пример #2
0
 /**
  * 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, 'pagination' => ['pageSize' => 1]]);
     $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, 'created_time' => $this->created_time, 'last_update' => $this->last_update]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'detail', $this->detail]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $productsCountSql = self::getProductsCountQuery('`pc`.`id`')->createCommand()->sql;
     $query = ProductCategory::find()->select(['`pc`.*', "({$productsCountSql}) AS `productsCount`"])->from(ProductCategory::tableName() . ' `pc`');
     $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([]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $dataProvider->sort = ['attributes' => ['name', 'productsCount'], 'defaultOrder' => ['name' => SORT_ASC]];
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->addParam('categoryId', $params);
     $query = Product::find()->select(['`p`.*', '`pc`.`name` AS `categoryName`'])->from(Product::tableName() . '`p`')->leftJoin(ProductCategory::tableName() . ' `pc`', '`p`.`category_id` = `pc`.`id`');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if (!isset($params['sort'])) {
         $query->orderBy('`p`.`name`');
     }
     $query->andFilterWhere(['`p`.`calories`' => $this->calories, '`p`.`protein`' => $this->protein, '`p`.`fat`' => $this->fat, '`p`.`carbohydrate`' => $this->carbohydrate, '`p`.`category_id`' => $this->categoryId, '`pc`.`name`' => $this->categoryName]);
     $query->andFilterWhere(['like', '`p`.`name`', $this->name])->andFilterWhere(['like', '`pc`.`name`', $this->categoryName]);
     $dataProvider->sort = ['attributes' => ['name', 'calories', 'protein', 'fat', 'carbohydrate', 'categoryName' => [SORT_ASC => '`pc`.`name` ASC', SORT_DESC => '`pc`.`name` DESC']]];
     return $dataProvider;
 }
Пример #5
0
    public function test_getSearchedItems()
    {
        /** Test 1 : tests method with all good inputs .. to be mocked later #TODO **/
        // Create 2 products as a setup
        $faker = Faker\Factory::create();
        for($i=0; $i< 2; $i++)
        {
            $input = array(
                'user_id'               => 1,
                'university_id'         => 20,
                'title'                 => $faker->sentence, 
                'description'           => $faker->paragraph(4),
                'primary_image_path'    => 'main_image_'.rand(1,4).'.jpeg',
                'delivery'              => 1,
                'pickup'                => 1,
                'free'                  => 1,
                'price'                 => 0
            );
            print_r($input);
            $product =  Product::create($input);
            ProductKeyword::create([
                    'product_id'   => $product->id,
                    'keyword_id'   => 10
                ]); 
            ProductKeyword::create([
                    'product_id'   => $product->id,
                    'keyword_id'   => 20
                ]); 
            ProductCategory::create([
                'product_id'   => $product->id,
                'category_id'  => 25
            ]);       

        }

        $whereIn['keyword_id'] = array(10, 20);
        $where['category_id'] = 25;
        $where['university_id'] = 20;
        $where['delivery'] = 1;
        $where['pickup'] = 1;
        $where['free'] = 1;
        $where['price'] = 0;
        $sort['products.updated_at'] = 'desc';
        
        $results = Product::getSearchedItems($where, $whereIn, $sort);
    } 
 public function actionCategory($categoryId)
 {
     $category = ProductCategory::findOne($categoryId);
     if (empty($category)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if ($this->isAjax()) {
         $model = new Recipe();
         $model->productCategoryId = $categoryId;
         return $this->renderPartial('@app/views/partials/_category-ingredients-dropdown-list', ['model' => $model, 'form' => ActiveForm::begin()]);
     } else {
         $params = Yii::$app->request->queryParams;
         $params['categoryId'] = $categoryId;
         $searchModel = new ProductRepository();
         $dataProvider = $searchModel->search($params);
         return $this->render(['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'categoryName' => $category->name]);
     }
 }
 /**
  * @return array
  */
 public function getProductCategoriesItems()
 {
     return ProductCategory::getItems();
 }
Пример #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCateg()
 {
     return $this->hasOne(ProductCategory::className(), ['id' => 'categ_id']);
 }
Пример #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductCategories()
 {
     return $this->hasMany(ProductCategory::className(), ['parent_id' => 'id']);
 }
Пример #10
0
        <?=
        GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
//            'id',
                'code',
                'name',
//                'detail:ntext',
//                'created_time',
                // 'last_update',
//                 'product_category_id',
                [
                    'attribute' => 'product_category_id',
                    'header' => Yii::t('app', 'Product Category'),
                    'filter' => Html::activeDropDownList($searchModel, 'product_category_id', ArrayHelper::map(\app\models\ProductCategory::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => Yii::t('app', 'All')]),
                    'value' => function ($data) {
                return $data->productCategory->name;
            }
                ],
                ['class' => 'yii\grid\ActionColumn',
                    'template' => '{update} {delete}'
                ],
            ],
        ]);
        ?>
        <?php Pjax::end() ?>
    </div>    
</div>
 /**
  * @return array
  */
 public function getIngredientsCategoriesListItems()
 {
     return ProductCategory::getItems();
 }
 /**
  * Finds the ProductCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return array
  */
 public function getCategoryIdItems()
 {
     if ($this->_categoryIdItems !== null) {
         return $this->_categoryIdItems;
     }
     $this->_categoryIdItems = [];
     $categories = ProductCategory::find()->orderBy('name')->asArray()->all();
     if (!empty($categories)) {
         foreach ($categories as $category) {
             $this->_categoryIdItems[$category['id']] = $category['name'];
         }
     }
     return $this->_categoryIdItems;
 }
Пример #14
0
 public function actionSearch()
 {
     $post = \Yii::$app->request->post();
     if (isset($post["code"])) {
         $category = ProductCategory::find()->where("code=:code", [":code" => $post["code"]])->one();
         if ($category) {
             echo json_encode(["id" => $category->id, "code" => $category->code, "name" => $category->name]);
         }
     } else {
         echo "";
     }
 }
Пример #15
0
 public function actionProductsales($groupBy = null)
 {
     $this->layout = 'dashboard';
     $model = new ProductSaleReportForm();
     $modelsales = new SaleOrder();
     $modelsaleine = new SaleOrderLine();
     // Data Category Product
     $category = ProductCategory::find()->all();
     $datacetegory = ArrayHelper::map($category, 'id', 'name');
     // Data Pricelist
     $pricelist = ProductPricelist::find()->where(['type' => 'sale'])->all();
     $datapricelist = ArrayHelper::map($pricelist, 'id', 'name');
     if ($model->load(Yii::$app->request->get())) {
         $query = $this->getSOLineRelatedQuery($model, $groupBy);
     } else {
         $query = $this->getSOLineRelatedQuery($model, $groupBy);
         $productcategory = null;
         $pricelist = null;
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'key' => 'id', 'pagination' => ['pageSize' => 100]]);
     if ($groupBy) {
         return $this->render('productsales_form', ['model' => $model, 'type' => 'search', 'dataProvider' => $dataProvider, 'groupBy' => $groupBy, 'datacetegory' => $datacetegory, 'datapricelist' => $datapricelist]);
     } else {
         return $this->render('productsales_form', ['model' => $model, 'type' => 'search', 'dataProvider' => $dataProvider, 'groupBy' => 'nogroup', 'datacetegory' => $datacetegory, 'datapricelist' => $datapricelist]);
     }
 }