[BUG] addPromotionCode adds success message in error object of cart response
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
I'm currently developing a custom, vue.js based checkout that communicates with a headless Shopware instance via API. After successfully adding a promotion with the provided method addPromtionCode() the cart response contains a success message in the error object:
{ "errors": { "promotion-discount-added-018bd22b81c575a59022a177143933c9": { "message": "Discount Test has been added", "code": 0, "key": "promotion-discount-added-018bd22b81c575a59022a177143933c9", "level": 0, "messageKey": "promotion-discount-added" } } }
A real cart error looks for me like the same, only the key of the message is different:
{ "errors": { "promotion-not-found": { "message": "Promotion with code notfound not found!", "code": 0, "promotionCode": "notfound", "key": "promotion-not-found", "level": 20, "messageKey": "promotion-not-found" } } }
Additionally the status code of the response with the real error is 200, so there is no good way to detect, that there was an error or an success. The only possibility I found, was to look at the messageKeys of the errors and filter the success messages.
This is highly annoying and the UX of this is not very good.
Expected Behavior
Rename the error object to messages and add a type flag to the messages as identifier if its a success, error, warning or info message.
E.g.:
{ "messages": [ { "message": "Promotion with code notfound not found!", "code": 0, "promotionCode": "notfound", "key": "promotion-not-found", "level": 20, "messageKey": "promotion-not-found", "type": "error", } } }
Steps To Reproduce
No response
Environment
- OS:
- Node:
- pnpm:
Anything else?
No response
@torbenWark thank you for the reporting. Unfortunately, this issue is related to the platform.
You can use useCartNotification composable to get errors from the cart, and for now, this is how we handle cart errors on the fronted app.
Of course, I agree that this should be unified.
@BrocksiNet or @patzick please move this task to the core if you have the possibility
Added to our list (NEXT-31800).