This tutorial was written with Symfony 5 and it's not compatible with version 6 at this time. In Symfony 6, the Session service has been removed. To get the Session, you now need to inject the RequestStack service and use the new getSession() method.
You need to upgrade the CartSessionStorage like that :
namespaceApp\Storage;useApp\Entity\Order;useApp\Repository\OrderRepository;useSymfony\Component\HttpFoundation\RequestStack;/**
* Class CartSessionStorage
* @package App\Storage
*/classCartSessionStorage{/**
* @var RequestStack
*/private$requestStack;/**
* The cart repository.
*
* @var OrderRepository
*/private$cartRepository;/**
* @var string
*/constCART_KEY_NAME='cart_id';/**
* CartSessionStorage constructor.
*
* @param RequestStack $requestStack
* @param OrderRepository $cartRepository
*/publicfunction__construct(RequestStack$requestStack,OrderRepository$cartRepository){$this->requestStack=$requestStack;$this->cartRepository=$cartRepository;}/**
* Gets the cart in session.
*
* @return Order|null
*/publicfunctiongetCart():?Order{return$this->cartRepository->findOneBy(['id'=>$this->getCartId(),'status'=>Order::STATUS_CART]);}/**
* Sets the cart in session.
*
* @param Order $cart
*/publicfunctionsetCart(Order$cart):void{$this->requestStack->getSession()->set(self::CART_KEY_NAME,$cart->getId());}/**
* Returns the cart id.
*
* @return int|null
*/privatefunctiongetCartId():?int{return$this->requestStack->getSession()->get(self::CART_KEY_NAME);}}
What version of Symfony are you using?
Symfony 6.0
This tutorial was written with Symfony 5 and it's not compatible with version 6 at this time. In Symfony 6, the Session service has been removed. To get the Session, you now need to inject the RequestStack service and use the new getSession() method.
You need to upgrade the
CartSessionStorage
like that :It worked! It seems that everything is good now.
Thanks!