Good afternoon, ran into this problem:
There are two tables in the database, one for the details of the order, and another for the goods of this order.
I make an order, in the first table (for details of the order) recorded data, and the second table recorded only 1 line, instead of 2, 3, etc. (For example, if 3 types of goods should be recorded 3 lines of goods, but I have written only one line).
$order = new Orders();
$items = new OrdersItems();
//Сохранение заказа ...
// ................
//Сохранение товаров
if ($order->order_id){
foreach ($_SESSION['cart'] as $item){
$items->order_id = $order->order_id;
$items->product = $item['name'];
$items->product_id = $item['product_id'];
$items->price = $item['price'];
$items->qty = $item['qty'];
$items->save();
}
$session =Yii::$app->session;
$session->open();
$session->remove('cart');
$session->remove('cart.qty');
$session->remove('cart.sum');
return $this->redirect(['orders/view', 'id' => $order->order_id]);
}else{
debug('Error!');
}