Feature request from Vinai, posted on GitHub Apr 21, 2016
Steps to reproduce
- Create a class with a dependency on
\Magento\Quote\Api\Data\CartInterface
- Add a product to the cart
- Execute the code within the same session
Expected result
- The
CartInterface instance represents the current quote
\Magento\Quote\Api\Data\CartInterface::getItems returns the items in the cart
Actual result
The injected CartInterface instance is empty.
To retrieve the current quote items \Magento\Checkout\Model\Session::getQuote() has to be used.
This is problematic since neither \Magento\Checkout\Model\Session nor \Magento\Quote\Model\Quote are blessed with the @api interface.
The alternative would be to use \Magento\Quote\Model\GuestCart\GuestCartRepository::get() or \Magento\Quote\Api\CartManagementInterface::getCartForCustomer, but for guests that would require having the masked cart id.
It is quite common for customizations to require access to the current cart contents. It would be nice if that could be handled with a simple dependency on CartInterface.