document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. php
  2. <?php
  3.  
  4. namespace Vendor\\Module\\Model;
  5.  
  6. use Magento\\Checkout\\Model\\Cart;
  7.  
  8. class YourClass
  9. {
  10. protected $cart;
  11.  
  12. public function __construct(Cart $cart)
  13. {
  14. $this->cart = $cart;
  15. }
  16.  
  17. public function getCartProducts()
  18. {
  19. $items = $this->cart->getQuote()->getAllVisibleItems();
  20. foreach ($items as $item) {
  21. $productName = $item->getName();
  22. $productQty = $item->getQty();
  23. // Additional product information can be accessed here
  24. }
  25. return $items;
  26. }
  27. }
');