K
K
Konstantin2017-06-21 06:05:43
Yii
Konstantin, 2017-06-21 06:05:43

Why is the same item added to the cart again and again?

public function actionTocart($id, $name, $price, $count = 1){
        $session = Yii::$app->session;
        $session->open();
        $_SESSION['cart'][$id]['name'] = $name;
        $_SESSION['cart'][$id]['price'] = $price;
        $_SESSION['cart'][$id]['count'] = $count;
        $this->redirect("/cart");
    }

has the following code. why when adding a new product to the cart will replace the old one. and actually always 1 product (last)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-06-21
@Sanasol

fea38fbb1165ed7f3c69dd22bac3.png
code picture is so convenient!
ps Why climb directly into the session?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question