public function getCartContents()

in Helper/MagentoDataHelper.php [241:259]


    public function getCartContents()
    {
        $cart = $this->objectManager->get(\Magento\Checkout\Model\Cart::class);
        if (!$cart || !$cart->getQuote()) {
            return null;
        }
        $contents = [];
        $items = $cart->getQuote()->getAllVisibleItems();
        $priceHelper = $this->objectManager->get(\Magento\Framework\Pricing\Helper\Data::class);
        foreach ($items as $item) {
            $product = $item->getProduct();
            $contents[] = [
                'product_id' => $product->getId(),
                'quantity' => $item->getQty(),
                'item_price' => $priceHelper->currency($product->getFinalPrice(), false, false)
            ];
        }
        return $contents;
    }