php
<?php
namespace Vendor\\Module\\Model;
use Magento\\Checkout\\Model\\Cart;
class YourClass
{
protected $cart;
public function __construct(Cart $cart)
{
$this->cart = $cart;
}
public function getCartProducts()
{
$items = $this->cart->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
$productName = $item->getName();
$productQty = $item->getQty();
// Additional product information can be accessed here
}
return $items;
}
}