I'm getting empty array without using session object. How we can get cart data without using session object.
Here is the screenshot:
Here is the code:
$cartItems = $this->cart->getAllVisibleItems();
I'm getting empty array without using session object. How we can get cart data without using session object.
Here is the screenshot:
Here is the code:
$cartItems = $this->cart->getAllVisibleItems();
I noticed that you are accessing allVisibleItems directly from the cart object. But first, you should retrieve the quote and then access allVisibleItems. This will resolve your issue.
Here is the correct code:
$this->cart->getQuote()->getAllVisibleItems();
you can can get cart data using this:-
$items = $this->cart->getQuote()->getAllItems();