I have one problem that I can't explain with my session manager. Well i built a very simple cart. It's create a key in the Symfony Session called "product_cart".
WhenIi come at the "cart page" for the first time, I see my products. But if I refresh the page, the session is empty...
There my cart action page
/**
* @Route("/{_locale}/submissions/cart", name="frontend_domilia_submissions_cart")
*/
public function indexAction(Session $session) {
return $this->render(':Frontend/Submissions:cart.html.twig', [
'products' => $session->get('product_cart'),
]);
}
/**
* @param Product $product
*/
public function addProductToBasket(Product $product) {
$basketProduct = new BasketProduct();
$basketProduct->setId(uniqid());
$basketProduct->setProductId($product->getId());
$basketProduct->setTitle($product->getTitle());
$basketProduct->setImagePath($product->getImageMain());
$basketProduct->setQty(1);
$productList = $this->session->get('product_cart');
if (is_null($productList)) {
$this->session->set('product_cart', [$basketProduct]);
} else {
array_push($productList, $basketProduct);
$this->session->set('product_cart', $productList);
}
}
I think something break my session but I don't know what, it's a little bit strange...
This happened only in dev mode.
Somebody could help me please? Regards, Christophe