/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function loadProduct($productId) { $product = Product::findOne($productId); if (!$product) { throw new HttpException(404, 'Товар не найден'); } return $product; }
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]); }
<a href="<?php echo Url::to(['/store/admin/manufacturer']); ?> ">Производители <i class="badge"><?php echo \app\modules\store\models\Manufacturer::getCount(); ?> </i></a> </li> <li> <a href="<?php echo Url::to(['/store/admin/product']); ?> ">Товары <i class="badge"><?php echo \app\modules\store\models\Product::getCount(); ?> </i></a> </li> <li> <a href="<?//= Url::to(['/store/admin/order']) ?>">Заказы <i class="badge"><?//= \app\modules\store\models\Order::getCount() ?></i></a> </li> </ul> </li --> <li> <a href="#"><i class="fa fa-android fa-fw"></i>Персонал<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li> <a href="<?php echo Url::to(['/directorBoard/admin/board']);
public function getProducts() { return $this->hasMany(Product::className(), ['manufacturerId' => 'id']); }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel app\modules\store\models\ProductSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Товары'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="product-index"> <p> <?php echo Html::a(Yii::t('app', 'Добавить'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['header' => '', 'format' => 'html', 'value' => function ($model) { return Html::img($model->image->resize()); }], ['attribute' => 'categoryId', 'value' => function ($model) { return $model->category->title; }, 'filter' => \app\modules\store\models\Category::dropDown()], ['attribute' => 'visible', 'value' => 'visibleDisplay', 'filter' => \app\modules\store\models\Product::visibleList()], 'title', 'alias', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function getProduct() { return $this->hasOne(Product::className(), ['categoryId' => 'id']); }