cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving the current quote requires use of non-@api methods.

Retrieving the current quote requires use of non-@api methods.

Feature request from Vinai, posted on GitHub Apr 21, 2016

Steps to reproduce

  1. Create a class with a dependency on \Magento\Quote\Api\Data\CartInterface
  2. Add a product to the cart
  3. Execute the code within the same session

Expected result

  1. The CartInterface instance represents the current quote
  2. \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.

2 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from piotrekkaminski, posted on GitHub May 23, 2016

Internal issue MAGETWO-53269