public function actionView($category, $alias) { /** @var $model Product */ $model = Product::find()->where(['alias' => $alias])->one(); if (!$model || $model->category->alias != $category) { throw new HttpException(404, 'Товар не найден'); } return $this->render('view', ['model' => $model]); }
public function getItems() { $session = $this->session; $productIds = array_keys($session); if (empty($productIds)) { return []; } $products = Product::find()->where(['id' => $productIds])->visible()->orderBy([new Expression('FIND_IN_SET(id,:productIds)')])->addParams([':productIds' => implode(',', $productIds)])->all(); foreach ($products as &$product) { $product->basketQuantity = $session[$product->id]->quantity; $this->total['quantity'] += $product->basketQuantity; } return $products; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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, 'categoryId' => $this->categoryId, 'manufacturerId' => $this->manufacturerId, 'minCount' => $this->minCount, 'quantity' => $this->quantity, 'visible' => $this->visible]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionBrand($alias) { /** @var $category Category */ $category = Manufacturer::find()->where(['alias' => $alias])->one(); if (!$category) { throw new HttpException(404, 'Категория товара не найдена'); } $q = \Yii::$app->request->get('q'); if (!empty($q)) { $products = Product::find()->where(['manufacturerId' => $category->id])->visible()->andWhere(['like', 'title', $q])->all(); } else { $products = $category->products; } $route = $this->route; $title = 'Товары - Производители - ' . $category->title; return $this->render('view', ['category' => $category, 'products' => $products, 'q' => $q, 'route' => $route, 'title' => $title]); }