/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCategoryToProduct::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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, 'product_category_id' => $this->product_category_id, 'product_id' => $this->product_id]);
     return $dataProvider;
 }
示例#2
0
 public function getProducts($params = [])
 {
     $cate_ids = ArrayHelper::merge([$this->id], ArrayHelper::getColumn($this->getChildren(), 'id'));
     $id_in = ArrayHelper::getColumn(ProductCategoryToProduct::find()->where(['in', 'product_category_id', $cate_ids])->all(), 'product_id');
     $result = Product::getProducts(['id_in' => $id_in, 'orderBy' => !empty($params['orderBy']) ? $params['orderBy'] : null, 'limit' => !empty($params['limit']) ? $params['limit'] : null, 'offset' => !empty($params['offset']) ? $params['offset'] : null]);
     return $result;
 }