Running Magento 2.3.1.
I'm having trouble understanding how to get the customer's checkout/cart session data from an external PHP script.
The script is hosted and run on the same domain as the Magento store, and it's located in Magento's root directory. I'm running it from the same browser. All caches are disabled.
I have 3 items in my Magento cart, but when I run the script, it does not find any items:
<?php require("app/bootstrap.php"); $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); // Set the state (not sure if this is neccessary) $state = $obj->get('Magento\Framework\App\State')->setAreaCode('frontend'); // Get cart items $quote = $obj->get('Magento\Checkout\Model\Session')->getQuote(); $quoteItems = $quote->getAllVisibleItems(); echo "Found " . count($quoteItems) . " cart items"; // Expected output: // Found 3 cart items // Actual output: // Found 0 cart items
P.S. Please do not comment that ObjectManager should not be used directly. It is not helpful, and this is for a one-off script on an internal development environment only.