Пример #1
0
 public function actionBasket()
 {
     if (Yii::$app->request->isPost) {
         $buyForm = new BuyForm();
         if (Yii::$app->request->post('delete') !== null) {
             if ($buyForm->load(Yii::$app->request->post()) && $buyForm->validate()) {
                 $result = Yii::$app->db->createCommand('call basket_delete(:user_id,:product_id);')->bindValue(':user_id', Yii::$app->user->identity->id)->bindValue(':product_id', $buyForm->product_id)->execute();
             } else {
                 $errors = $buyForm->errors;
             }
         } else {
             if ($buyForm->load(Yii::$app->request->post()) && $buyForm->validate()) {
                 $result = Yii::$app->db->createCommand('call basket_update(:user_id,:product_id,:count);')->bindValue(':user_id', Yii::$app->user->identity->id)->bindValue(':product_id', $buyForm->product_id)->bindValue(':count', $buyForm->count)->execute();
             } else {
                 $errors = $buyForm->errors;
             }
         }
     }
     $basket = Yii::$app->db->createCommand('call basket_list(:user_id)')->bindValue(':user_id', Yii::$app->user->identity->id)->queryAll();
     return $this->render('basket', ['basket' => $basket]);
 }
Пример #2
0
 public function actionView()
 {
     $db = Yii::$app->db;
     $product = $db->createCommand('call product_view_' . Yii::$app->request->get('category') . '(:id);')->bindValue(':id', (int) Yii::$app->request->get('id'))->queryOne();
     $breadcrumbsBranch = Page::treeBranch('products');
     $breadcrumbsBranch[] = ['header' => $product['category_header'], 'sid' => $product['category_sid']];
     $breadcrumbsBranch[] = ['header' => htmlspecialchars_decode($product['header'])];
     $buyForm = new BuyForm();
     if (Yii::$app->request->isPost) {
         if (Yii::$app->request->post('delete') !== null) {
             echo "<pre>";
             print_r($_POST);
             echo "</pre>";
             die;
             $result = Yii::$app->db->createCommand('call basket_delete(:user_id,:product_id);')->bindValue(':user_id', Yii::$app->user->identity->id)->bindValue(':product_id', $product['id'])->execute();
         } else {
             $buyForm->load(Yii::$app->request->post());
             if ($buyForm->validate()) {
                 $result = Yii::$app->db->createCommand('call basket_insert(:user_id,:product_id,:count);')->bindValue(':user_id', Yii::$app->user->identity->id)->bindValue(':product_id', $product['id'])->bindValue(':count', $buyForm->count)->execute();
             } else {
                 $errors = $model->errors;
             }
         }
     }
     $count = Yii::$app->db->createCommand('call basket_count(:user_id,:product_id);')->bindValue(':user_id', Yii::$app->user->identity->id)->bindValue(':product_id', $product['id'])->queryOne();
     $buyForm->user_id = Yii::$app->user->identity->id;
     $buyForm->product_id = $product['id'];
     $buyForm->count = 1;
     return $this->render(Yii::$app->request->get('category'), ['count' => $count['count'], 'buyForm' => $buyForm, 'product' => $product, 'breadcrumbsBranch' => $breadcrumbsBranch]);
 }