0

I'm getting empty array without using session object. How we can get cart data without using session object.

Here is the screenshot:

enter image description here

Here is the code:

$cartItems = $this->cart->getAllVisibleItems();

2
  • Hi @Alan Which class/interface you are using for the cart object? Commented Jan 10 at 5:12
  • Alan, could you please try the solution provided below. Commented Jan 10 at 5:35

2 Answers 2

3

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();
1

you can can get cart data using this:-

$items = $this->cart->getQuote()->getAllItems();
1
  • 1
    yess thta's the correct
    – Jay Parmar
    Commented Jan 10 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.