Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Basket::find()->where(['user_id' => Yii::$app->user->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //var_dump($params);
     //die();
     $dataProvider->setSort(['attributes' => ['id', 'count', 'summ', 'good_id' => ['default' => SORT_ASC], 'good_1c' => ['asc' => ['good_id' => SORT_ASC], 'desc' => ['good_id' => SORT_DESC]]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith('goods');
     $query->andFilterWhere(['id' => $this->id, 'count' => $this->count, 'summ' => $this->summ * 100 == 0 ? '' : $this->summ * 100])->andFilterWhere(['like', 'goods.good_name', $this->good_id])->andFilterWhere(['like', 'goods.good_1c_id', $this->good_1c]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Finds the Basket model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Basket the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Basket::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionInsertall($order_id)
 {
     $basket = Basket::findAll(['user_id' => Yii::$app->user->id]);
     //for($i=0; $i < Basket::getCount(); $i++){
     foreach ($basket as $modelb) {
         //$modelb = $basket[$i];
         //echo $modelb->good_id .' '. $modelb->count .' '. $modelb->summ .' '. $modelb->user_id . '<br>';
         $model = new Listofgoods();
         $model->orders_order_id = (int) $order_id;
         $model->goods_good_1c_id = (string) $modelb->good_id;
         $model->good_count = (int) $modelb->count;
         $model->save();
     }
     Basket::deleteAll(['user_id' => Yii::$app->user->id]);
     return $this->redirect(['orders/view', 'id' => $order_id]);
     //var_dump($basket);
     //die();
 }
Beispiel #4
0
<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>