/** * * @param integer $good_id * @param integer $count * @param float $price */ public function actionInsert() { $post = Yii::$app->request->post(); $a = 0; foreach ($post as $key => $item) { if (strcasecmp($key, 'GoodsSearch') == 0) { continue; } //пропускаем параметры поиска //собираем данные if (FALSE !== strpos($key, 'count')) { $count = $item; $a++; } if (FALSE !== strpos($key, 'good')) { $good = $item; $a++; } if (FALSE !== strpos($key, 'price')) { $price = $item; $a++; } if ($a == 3) { if ($count == 0) { $count = 0; $good = 0; $price = 0; $a = 0; continue; } //echo '->' . $count .' '. $good .' '. $price . '<br>'; $model = new Basket(); $model->user_id = Yii::$app->user->id; $model->good_id = $good; //$post = Yii::$app->request->post(); $model->count = $count; $model->summ = $count * $price; //тут цена приходит целым числом - корректировать не надо $model->save(); $count = 0; $good = 0; $price = 0; $a = 0; } } //$page = ceil($str / 20); return $this->redirect(['orders/create', 'amount' => Basket::getTotals('summ') / 100]); }
<div class="basket-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Открыть каталог', ['goods/index'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'good_id', 'value' => 'goods.good_name'], ['attribute' => 'good_1c', 'value' => 'goods.good_1c_id'], 'count', ['attribute' => 'summ', 'value' => function ($model) { return $model->summ / 100; }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}']]]); ?> <div align="right"> <?php //$arr = Basket::getTotals(); echo '<strong>Всего товаров в корзине: ' . Basket::getTotals('count') . '. На сумму: ' . Basket::getTotals('summ') / 100 . ' </strong>'; echo Html::a('Оформить заказ', ['orders/create', 'amount' => Basket::getTotals('summ') / 100], ['class' => 'btn btn-success']); ?> </div> </div>