예제 #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;
 }
예제 #2
0
파일: Price.php 프로젝트: oakcms/oakcms
 public static function editField($id, $name, $value)
 {
     $setting = Price::findOne($id);
     $setting->{$name} = $value;
     $setting->save();
 }
예제 #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;
 }
예제 #4
0
파일: Product.php 프로젝트: oakcms/oakcms
 public function afterDelete()
 {
     parent::afterDelete();
     Price::deleteAll(["product_id" => $this->id]);
     return false;
 }
예제 #5
0
파일: index.php 프로젝트: oakcms/oakcms
?>
        </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\" />";
    }