コード例 #1
0
 /**
  * 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.');
     }
 }
コード例 #2
0
 protected function loadProduct($productId)
 {
     $product = Product::findOne($productId);
     if (!$product) {
         throw new HttpException(404, 'Товар не найден');
     }
     return $product;
 }
コード例 #3
0
 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]);
 }
コード例 #4
0
ファイル: Basket.php プロジェクト: nurastana/familyclinickz
 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;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 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]);
 }
コード例 #7
0
                        <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']);
コード例 #8
0
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['manufacturerId' => 'id']);
 }
コード例 #9
0
ファイル: index.php プロジェクト: nurastana/familyclinickz
<?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>
コード例 #10
0
ファイル: Category.php プロジェクト: nurastana/familyclinickz
 public function getProduct()
 {
     return $this->hasOne(Product::className(), ['categoryId' => 'id']);
 }