When I have created a block to the show a custom success message on the checkout page. I have used

$this->messageManager->addSuccess(__('your' .$currencySymbol.$amount. ' amount' ));

But when I am running the code I got this type of error: Recoverable Error: Object of class Magento\Framework\Message\Manager could not be converted to string in "my file path".

Please help me. How to solve my error?

Thank you very much.

  • Show how you get $currencySymbol and $amount? – Sohel Rana Jul 6 '19 at 4:18
  • $amount=500; $this->messageManager->addSuccess(__('your' .$amount.' amount' )); try this code if msg print correctly , the issue is your $currencySymbol.$amount values not working properly – Shafeel Sha Jul 6 '19 at 5:03
  • I get currecncy symbol using $this->_storeManager->getStore()->getCurrentCurrencyCode(); and amount $this->_checkoutSession->getQuote()->getSubtotal();. – Monark Bhawani Jul 6 '19 at 5:03
  • $ccode = $this->_storeManager->getStore()->getCurrentCurrencyCode(); $amount =$this->_checkoutSession->getQuote()->getSubtotal(); echo $ccode; echo $amount; die; //please check the values are proper working – Shafeel Sha Jul 6 '19 at 5:06
  • @ShafeelSha all values are working properly. If I print only "hello" then show in cart page, but when I code $this->messageManager->addSuccess(__('hello' )); then show error. – Monark Bhawani Jul 6 '19 at 5:52

If you are using Block and you return the message in return then don't do that just set the message in the messageManager and return true. You just set the message don't return to the phtml file.

Like just leave it $this->messageManager->addSuccess(__('your' .$currencySymbol.$amount. ' amount' ));

Not trying to set in return like this return $this->messageManager->addSuccess(__('your' .$currencySymbol.$amount. ' amount' ));

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.