A
A
Alexander Gorkin2018-08-07 21:44:21
Yii
Alexander Gorkin, 2018-08-07 21:44:21

How to set a condition for checking the amount in the cart?

The question is. I need a condition, for example, if the basket amount is < 20000r, then false, else true.
How can this be represented in the controller?

public function actionView() {
        $session=Yii::$app->session;
        $session->open();
        //$this -> setMeta('Корзина');
        $orders = new Orders();
        if ($orders->load(Yii::$app->request->post())){
            $orders->qty = $session['cart.qty'];
            $orders->sum = $session['cart.sum'];
            if($orders->save()) {
                $this->saveOrdersItem($session['cart'], $orders->id);
                Yii::$app->session->setFlash('success', 'Ваш заказ принят, менеджер свяжется с вами.');
                $session->remove('cart');
                $session->remove('cart.qty');
                $session->remove('cart.sum');
                return $this->refresh();
            } else Yii::$app->session->setFlash('success', 'Ошибка оформления заказа');
        }
        return $this->render('view', compact('session', 'orders'));
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-08-07
@mrbagfreeman

In my opinion, this is obvious:
or if you need to customize the logic, then

if($orders->sum < 20000){
  //тут если условие выполнено
}else{
  //тут если условие не выполнено
}

At what it is absolutely not important in the controller it or somewhere else.
Unless of course there is a number and not a string with the amount and the name of the currency.
I highly recommend reading at least the first paragraph on php, how do you plan to work with the language without knowing it at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question