コード例 #1
0
ファイル: CategorySearch.php プロジェクト: pistol88/yii2-shop
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => new \yii\data\Sort(['attributes' => ['name']])]);
     $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, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: _form.php プロジェクト: pistol88/yii2-shop
    

	
    <div class="row">
        <div class="col-lg-6 col-xs-6">
            <?php 
echo $form->field($model, 'category_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
            
            <?php 
echo $form->field($model, 'producer_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Producer::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите бренд ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-lg-6 col-xs-6">
            <?php 
echo $form->field($model, 'category_ids')->label('Прочие категории')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['multiple' => true, 'placeholder' => 'Доп. категории ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
    </div>

    <?php 
echo $form->field($model, 'text')->widget(\yii\imperavi\Widget::className(), ['plugins' => ['fullscreen', 'fontcolor', 'video'], 'options' => ['minHeight' => 400, 'maxHeight' => 400, 'buttonSource' => true, 'imageUpload' => Url::toRoute(['tools/upload-imperavi'])]]);
?>

    <?php 
echo $form->field($model, 'short_text')->textInput(['maxlength' => true]);
?>

	<?php 
echo Gallery::widget(['model' => $model]);
?>
コード例 #3
0
ファイル: Category.php プロジェクト: pistol88/yii2-shop
 public function getParent()
 {
     return $this->hasOne(Category::className(), ['id' => 'parent_id']);
 }
コード例 #4
0
ファイル: index.php プロジェクト: pistol88/yii2-shop
><a href="<?php 
echo Url::toRoute(['category/index', 'view' => 'tree']);
?>
">Деревом</a></li>
        <li role="presentation" <?php 
if (yii::$app->request->get('view') == 'list') {
    echo ' class="active"';
}
?>
><a href="<?php 
echo Url::toRoute(['category/index', 'view' => 'list']);
?>
">Списком</a></li>
    </ul>
    
    <br style="clear: both;">
    <?php 
if (isset($_GET['view']) && $_GET['view'] == 'list') {
    $categories = \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', ['attribute' => 'image', 'format' => 'image', 'filter' => false, 'content' => function ($image) {
        if ($image = $image->getImage()->getUrl('50x50')) {
            return "<img src=\"{$image}\" class=\"thumb\" />";
        }
    }], ['attribute' => 'parent_id', 'filter' => Html::activeDropDownList($searchModel, 'parent_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'parent.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 125px;']]]]);
} else {
    $categories = \pistol88\tree\widgets\Tree::widget(['model' => new \pistol88\shop\models\Category()]);
}
echo $categories;
?>

</div>
コード例 #5
0
ファイル: Showcase.php プロジェクト: pistol88/yii2-shop
 public function run()
 {
     $categories = Category::find()->all();
     return $this->render('showCase', ['categories' => $categories]);
 }
コード例 #6
0
ファイル: Product.php プロジェクト: pistol88/yii2-shop
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('{{%shop_product_to_category}}', ['product_id' => 'id']);
 }
コード例 #7
0
ファイル: _form.php プロジェクト: pistol88/yii2-shop
?>
    
    <?php 
echo $form->field($model, 'slug')->textInput(['placeholder' => 'Не обязательно']);
?>
	
	<?php 
echo $form->field($model, 'sort')->textInput();
?>
	
    <?php 
echo $form->field($model, 'text')->widget(\yii\imperavi\Widget::className(), ['plugins' => ['fullscreen', 'fontcolor', 'video'], 'options' => ['minHeight' => 400, 'maxHeight' => 400, 'buttonSource' => true, 'imageUpload' => Url::toRoute(['tools/upload-imperavi'])]]);
?>
    
    <?php 
echo $form->field($model, 'parent_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(null, 1, [$model->id]), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
    
    <?php 
echo Gallery::widget(['model' => $model]);
?>

    <?php 
echo \pistol88\seo\widgets\SeoForm::widget(['model' => $model, 'form' => $form]);
?>
        
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Изменить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
コード例 #8
0
ファイル: index.php プロジェクト: pistol88/yii2-shop
        <?php 
if ($amount = $dataProvider->query->sum('amount')) {
    ?>
            <div class="summary">
                Всего товаров:
                <?php 
    echo $amount;
    ?>
                на сумму
                <?php 
    echo Price::find()->joinWith('product')->sum("shop_price.price*shop_product.amount");
    ?>
 руб.
            </div>
        <?php 
}
?>
    
    <br style="clear: both;"></div>
    <?php 
echo \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', 'code', ['label' => 'Остаток', 'content' => function ($model) {
    return "<p>{$model->amount} (" . $model->amount * $model->price . ")</p>";
}], ['attribute' => 'images', 'format' => 'images', 'filter' => false, 'content' => function ($image) {
    if ($image = $image->getImage()->getUrl('50x50')) {
        return "<img src=\"{$image}\" class=\"thumb\" />";
    }
}], ['label' => 'Цена', 'value' => 'price'], ['attribute' => 'category_id', 'filter' => Html::activeDropDownList($searchModel, 'category_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'category.name'], ['attribute' => 'producer_id', 'filter' => Html::activeDropDownList($searchModel, 'producer_id', ArrayHelper::map(Producer::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Производитель']), 'value' => 'producer.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 125px;']]]]);
?>

</div>