4

Maybe due to our configuration (maybe due to M2), error messages are not printed anymore in Onepage checkout.

  • It's a simple case of throwing a \LocalizedException during capture() for reason X. That results in a 400 response for the /V1/carts/mine/payment-information request. All good.
  • M2 creates a JSON out of that exception, with a message property, which is then handled here. Superb.
  • The error message is then pushed onto an error message container here. Omg, brilliant.
  • Then nothing happens, what.

I was expecting the error message to be printed. Mind you, the above behaviour was tracked down with a JS debugger, I'm not assuming it happens.

Trying to fix this, I've stumbled upon \Magento\Framework\Message\ManagerInterface. Using that in my capture() method, it correctly added another message which this time was fetched with that customer/section/load request I dearly hate. And, although the messages property of the response was what I wanted, I still couldn't see my message appear.

Ok...

Then I saw that, for checkout only, M2 removes the messages container in favour of UI Components. It was too simple, you see. They had to put JSON in HTML through a PHP-parsed XML.

If I put back that message block, the message is finally showing, hooray. But I don't think M2 devs removed that block by mistake.

Do any of you know how exactly the JS message container does its job? Who triggers its rendering?

  • I tracked that bit of code back to this commit on beta16: github.com/magento/magento2/commit/… -Not clear what duplication the commit refers to, though, or how it's supposed to work alternatively. – Ryan Hoerr May 17 '16 at 2:18
  • Did you ever solve this without modifying xml of checkout? – belfort1 Sep 13 '16 at 7:44
  • How did you put the message back? – stephen Apr 7 '17 at 13:16
  • It was a year ago. Who knows what I did then... Sorry. – nevvermind Apr 7 '17 at 14:39