0

in my controller, I have this code (I'm getting last order through a form):

...
    foreach($array as $item){
                        try {
                            $product = $this->_productRepository->getById($item['product_id']);
                            $product_id = $product->getId();
                        } catch (NoSuchEntityException $e) {
                            echo $e;
                        }

                        if(isset($product_id)){
                            $param = array(
                                    'product' => $item['product_id'],
                                    'qty' => $item['qty']
                                );


                 }
                }

I want to display a simple message on my view. The exception is way to big, I want only to show 'product doesn't exist'. How can I do that ? I saw that I can achieve this with "message manager", but how can I get the exception from the controller to my view ?

5
  • $e->getMessage()tried this?
    – Gagan
    Commented Jul 26, 2018 at 10:13
  • 1
    $this->messageManager->addError('product doesn't exist');
    – Gagan
    Commented Jul 26, 2018 at 10:14
  • Where do I add this ? On frontend ? Commented Jul 26, 2018 at 10:18
  • No in place of echo $e; magento.stackexchange.com/questions/83138/…
    – Gagan
    Commented Jul 26, 2018 at 10:33
  • Yes that's it, I've understood a few minutes ago, thanks ! Commented Jul 26, 2018 at 12:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.