コード例 #1
0
ファイル: ProducerSearch.php プロジェクト: pistol88/yii2-shop
 public function search($params)
 {
     $query = Producer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new \yii\data\Sort(['attributes' => ['name', 'id']])]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: _form.php プロジェクト: pistol88/yii2-shop
            <?php 
echo $form->field($model, 'sort')->textInput();
?>
        </div>
    </div>
    

	
    <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]);
コード例 #3
0
ファイル: Product.php プロジェクト: pistol88/yii2-shop
 public function getProducer()
 {
     return $this->hasOne(Producer::className(), ['id' => 'producer_id']);
 }
コード例 #4
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>