Ejemplo n.º 1
0
 public function search($params)
 {
     $query = Price::find()->orderBy('sort DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'available' => $this->available]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public static function editField($id, $name, $value)
 {
     $setting = Price::findOne($id);
     $setting->{$name} = $value;
     $setting->save();
 }
Ejemplo n.º 3
0
 public function getPrice($type = 'lower')
 {
     $price = $this->hasOne(Price::className(), ['product_id' => 'product_id']);
     if ($type == 'lower') {
         $price = $price->orderBy('price ASC')->one();
     } elseif ($type) {
         $price = $price->where(['type_id' => $type])->one();
     } elseif ($defaultType = yii::$app->getModule('shop')->getPriceTypeId($this)) {
         $price = $price->where(['type_id' => $defaultType])->one();
     } else {
         $price = $price->orderBy('price DESC')->one();
     }
     if ($price) {
         return $price->price;
     }
     return null;
 }
Ejemplo n.º 4
0
 public function afterDelete()
 {
     parent::afterDelete();
     Price::deleteAll(["product_id" => $this->id]);
     return false;
 }
Ejemplo n.º 5
0
?>
        </div>
    </div>

    <?php 
if ($amount = $dataProvider->query->sum('amount')) {
    ?>
    <div class="summary">
            Всего остатков: Всего товаров:
            <?php 
    echo $amount;
    ?>
        </div>
        на сумму
        <?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\" />";
    }