Recently, I was trying to extend quote item with extension attributes. I needed it inside cart and checkout. So there are actually two ways for loading and persisting extension attributes along extended model.
First is creating plugins on repository of entity which has these new attributes.
For CartItemRepository this maybe would work for webapi - inside cart, checkout quote items are loaded in other ways - sometimes from qoute - by items collection, sometimes by directly loading model. It turns out that CartItemRepository is not very useful in frontend. Here comes also other grave problem - service contracts vs ,methods loading/returing/requiring concret implementations - many cases for quote and quote item.
Second way is adding handles to ExtensionPool, but it requires resource model using EntityManager, which is is not recommended . Despite of this for qoute item it is imposible, beacause, crud operations are performed in 'old-fashioned' way.
Finally, to perform crud operations on cart and checkout, with main logic in subtotals I ended up with plugins for three classes and override 5 methods - quote items are not loaded in any consistent way.
Examples (*)
Hard to provide - generally module doesn't seem to follow general guidelines from Magento.
Proposed solution
Clean up crud operations for quote and quote item, so service contract are used more widely on frontend, so we are not relying on implementations, but on contracts.
Summary (*)
Recently, I was trying to extend quote item with extension attributes. I needed it inside cart and checkout. So there are actually two ways for loading and persisting extension attributes along extended model.
CartItemRepository
this maybe would work for webapi - inside cart, checkout quote items are loaded in other ways - sometimes fromqoute
- by items collection, sometimes by directly loading model. It turns out thatCartItemRepository
is not very useful in frontend. Here comes also other grave problem - service contracts vs ,methods loading/returing/requiring concret implementations - many cases forquote
andquote item
.ExtensionPool
, but it requires resource model usingEntityManager
, which is is not recommended . Despite of this for qoute item it is imposible, beacause, crud operations are performed in 'old-fashioned' way.Finally, to perform crud operations on cart and checkout, with main logic in subtotals I ended up with plugins for three classes and override 5 methods -
quote items
are not loaded in any consistent way.Examples (*)
Hard to provide - generally module doesn't seem to follow general guidelines from Magento.
Proposed solution
Clean up crud operations for
quote
andquote item
, so service contract are used more widely on frontend, so we are not relying on implementations, but on contracts.