How can I get all data from cart

Is it possible to get check if cart has any product been added in. I want to check if a product been added to the cart in a phtml page. If the user click the page I want to show how many product they added in just the quantity If there is nothing show 0

Is this possible


Do you mean any logic to get cart contents. If so this should offer all the explanation you need.

In addition to this you need to add a count.

So count($block->cart->getQuote()->getAllVisibleItems()) for example

If I have misunderstood can you add more detail.

Similar questions

Upgrade Magento while keeping all order data, sales data, ect
Is there a definitive way to upgrade Magento while keeping all order data, sales data, ect? After setting up a staging environment and ensuring all extensions, ect. are working properly there will inevitably be orders placed, orders processed, ect. Is there a proper way to sync the data with the production installation? An alternative way I've read...
Get sum of cart quantity of all options for a configurable product on cart page
I want to get sum of qty of all variations present in cart for a configurable product. For ex.- see below image-- 'WHEY PROTEIN ISOLATE-WPI' is a configuration product. In cart it has 2 different variations with qty 1 and 2. I want to get its total qty i.e 3 (1+2) on same page (cart page), how can I get it. Although I can do it by looping for each ...
Is there any way to get all Applied Discount (for cart rules and coupons) line items in cart/order in Magento 2?
I need to show all cart/order discounts in the following manner: Magento 2 store only the coupon_code and the applied_rule_ids, but not the discount amount for specific rule and discount description. What would the best way to achieve this? (also if there is any module available, please suggest)
how to get all coupon code which can apply on cart page in magento 2
How to get all coupon code which can apply on cart page in magento 2 $getRules = $objectManager->create('Magento\SalesRule\Model\Rule')->getCollection(); using the above code i get the all list of coupon codes. I want to display coupon code which can apply
How can I get post data when adding a product to cart?
Tested and searched on this.. believe me. I have created a form which when submitted adds a specific product to the cart. An input will look like this for example: I am now trying to get that form's data in my observer (in a custom module). The event I thought best to hook onto is checkout_cart_add_product_complete as it provides: I've tried lots o...
How can i give condition Shopping Cart Price Rules like if selected attribute products present in the cart, no other products allowed to add cart
If the customer selects my custom attribute products like "XYZ" to cart, after the customer not able to add other products to cart, the message showed "XYZ" attribute products present in the cart. and also other attributes products present in the cart, not able to add my "XYZ" attributes products to cart. How can I do it by using Shopping Cart Pric...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.