Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CartItemInterface cannot add extension_attributes #3640

Closed
degaray opened this issue Mar 3, 2016 · 7 comments
Closed

CartItemInterface cannot add extension_attributes #3640

degaray opened this issue Mar 3, 2016 · 7 comments
Assignees
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@degaray
Copy link

degaray commented Mar 3, 2016

I am trying to extend CartItemInterface with custom attributes. It goes well, in most parts, but it crashes when calling /carts/mine/payment-information. This is the error I get:

  "message": "Recoverable Error: Argument 1 passed to Magento\Quote\Model\Cart\Totals\Item::setExtensionAttributes() must be an instance of Magento\Quote\Api\Data\TotalsItemExtensionInterface, instance of Magento\Quote\Api\Data\CartItemExtension given, called in /vagrant/data/magento2/lib/internal/Magento/Framework/Api/DataObjectHelper.php on line 125 and defined in /vagrant/data/magento2/app/code/Magento/Quote/Model/Cart/Totals/Item.php on line 470",
  "trace": "#0 /vagrant/data/magento2/app/code/Magento/Quote/Model/Cart/Totals/Item.php(470): 

@mitul69
Copy link

mitul69 commented Mar 4, 2016

hey @degaray

Have you added dependency in your di.xml file?

@ishakhsuvarov
Copy link
Contributor

@degaray Thank you for reporting. We already have a similar item in our backlog (internal ticket MAGETWO-50025) to investigate this.

@ishakhsuvarov ishakhsuvarov added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development CS labels Mar 4, 2016
@ishakhsuvarov ishakhsuvarov self-assigned this Mar 4, 2016
@degaray
Copy link
Author

degaray commented Mar 4, 2016

Thanks. Do you have a workaround?

@ishakhsuvarov
Copy link
Contributor

@degaray I'm afraid we don't have one currently. We will update this ticket as soon as some more information is available.
Thank you.

@degaray
Copy link
Author

degaray commented Mar 4, 2016

Ok, here is what I have found so far. If you create an extension_attribute for Magento\Quote\Api\Data\CartItemInterface it works well. However when you call /carts/mine/payment-information Magento tries to convert the CartItemInterface into a Magento\Quote\Model\Cart\Totals\TotalsItemInterface. The problem is that at certain point in the conversion specifically in Magento\Framework\Api\DataObjectHelper::_setDataValues (125) it tries to run TotalItem's setExtensionAttribute, and it tries to set it with CartItem's extension_attributes. Since CartItem's extension_attributes has a different type than TotalItem's it gives the exception.
My best guess is you should convert the extension_attributes type in Magento\Quote\Model\Cart\CartTotalRepository::get before populateWithArray.

@ishakhsuvarov
Copy link
Contributor

@degaray Closing this ticket, as the fix seems to be delivered with the linked commit. Please feel free to reopen if you have any additional questions.

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-69223

@magento-team magento-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Jul 31, 2017
magento-engcom-team pushed a commit that referenced this issue Jan 27, 2019
[EngCom] Public Pull Requests - 2.3-develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

4 participants