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; }
public static function editField($id, $name, $value) { $setting = Price::findOne($id); $setting->{$name} = $value; $setting->save(); }
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; }
public function afterDelete() { parent::afterDelete(); Price::deleteAll(["product_id" => $this->id]); return false; }
?> </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\" />"; }