I have two table with OneToMany relation eg:
item
id|product_name|price|description
id|product xyz |12$ |blah blah
sizeAttriButes
id: size
1: XL
2: XXL
On the product view page the size is in Dropdown.
what I want to achieve here is when I click on the add to cart I want to fetch exact size attr in Cart. In single add to cart, it works, but in multi product the size is repeating, I want to achieve the following:
id|product_name|price|description|size
1 |product xyz |12$ |blah blah | XL
2 |product abc |15$ |blah blah | XXL
I'm doing following:
$basket = $session->get('basket',[]);
if($request->isMethod('POST')){
$product_size = $request->get('size');
$basket[$product->getId()] = $product;
$session->set('basket', $basket);
$session->set('size', $product_size);
}
cart:
{
$basket = $session->get('basket',[]);
$size = $session->get('size');
if($request->isMethod('POST')){
unset($basket[$request->request->get('id')]);
$session->set('basket', $basket);
}
$price = array_sum(array_map(function($product){
return $product->getPrice();
},
$basket
));
return $this->render('cart/cart.html.twig',[
'basket' => $basket,
'price' => $price,
'size' => $size
]);
}
enter image description here enter image description here
I might be doing wrong.. Please guide me...