1

I have submitted one module in the Magento Marketplace. I got error:

"Use of die language construct is discouraged".

Module is written by another programmer, I don't know how to change it to fix the problem.

I tried to find solution. Standard recommendation is using setBody(). But the Observer class does not have this method.

Code of invalid class:

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\DataObject as Object;

class RenderPopup implements ObserverInterface
{
    protected $_request;

    public function __construct(
        \Magento\Framework\View\Element\Context $context
    ) {
        $this->_request = $context->getRequest();
    }


    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->_request->getParam('quickview')) {
            if ($observer->getEvent()->getElementName() == 'main') {
                print_r($observer->getEvent()->getTransport()->getData('output')); 
                die;
            }
        }

    }
}
1

This code is totally useless, the only reason I can see an usage is for debugging purpose.

My suggestion:

  • Back it up
  • Delete it
  • Remove the corresponding entries in the events.xml files of your module
6
  • Don't you have any other solution? Your solution like a hack. – Oboroten Apr 11 '17 at 7:48
  • @Oborotenby did you read my answer ? The code you posted DOES NOT DO anything. It's totally useless so you can get rid of the file itself. – Raphael at Digital Pianism Apr 11 '17 at 8:32
  • I understood it. But if the code is useful, what would I need to print some text? – Oboroten Apr 11 '17 at 9:57
  • @Oborotenby what event does it observe ? – Raphael at Digital Pianism Apr 11 '17 at 9:58
  • 1
    @Oborotenby well it depends on the event you're observing. But usually you either call return $this; or you redirect. – Raphael at Digital Pianism Apr 11 '17 at 10:18

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.