31

Since Magento 2.1, Cart has a @deprecated tag. Nevertheless, it is still used by Magento itself to store products when shopping. Is the deprecation intended, and if so, and what should we use instead?

  • Welcome to Magento.SE! Great question! You may think to revise the title a bit so it doesn't ask for subjective answer. For instance, "Should I still use?" is probably better than "why was it deprecated" – philwinkle Jun 24 '16 at 14:52
  • Thanks for your reply, philwinkle! However, @deprecated already implies that it should not be use anymore. I just wanted to know what it is replaced by, and because it is still actively used by Magento, I have a small suspicion that the class was deprecated by mistake. :) – Patrick van Bergen Jun 24 '16 at 15:02
  • Outside of a core team member the answer cannot be canonically answered. But I think that as it stands it is a perfectly valid question. – philwinkle Jun 24 '16 at 15:32
  • for the record. deprecation removed in github.com/magento/magento2/pull/11070 – M.Elwan Mar 31 '18 at 21:51
23

My guess is that the Magento team is planning to implement service contracts for this class.

However as of 2.1 if you check the app/code/Magento/Checkout/Api folder there's no class (yet) that implements such service contract.

I assume it'll happen at some point and the Magento team flagged that model to be deprecated in the future. However as I said and as you said, it is still used in the software so you can still keep using it for now.

I reckon this @deprecated tag is a similar flag as the one for the load() method from Magento\Framework\Model\AbstractMode

Same goes for the XML <action> tag which is deprecated but still is the only option in some cases: http://goo.gl/laVP35 and is still widely used in 2.1: https://github.com/magento/magento2/search?l=xml&q=action&utf8=%E2%9C%93

17

The commit that deprecated the cart model is c4e9a77403655646a18d4277de96429c86bd34fa with the message

MAGETWO-51558: Mark Checkout Cart model as deprecated

This doesn't tell much, especially since this is the only commit that references the internal ticket number "MAGETWO-51558"

Since \Magento\Checkout\Api still does not contain any new service contracts and \Magento\Quote\Api\CartItemRepositoryInterface cannot replace the cart model either, I agree with your suspicion that it has been deprecated too early.

Of course, a final answer can only be given by a Magento employee.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.