0

I'm facing a weird issue. I had to override the Magento_contact Post Controller. Just adding a field on the contact form and the redirect after form is submitted, something easy, and all goes okay on developer mode.

But when I changed to production mode, when I submit the form, it appears "There has been an error processing your request"

I see the report, but it's only a warning, I don't know where it comes... I attach the report at the end.

I remember that error ocurred when I was implementing that feature, I changed some lines (don't remember exactly what I did) and it seems that worked...

And now suddenly I wanted to try again and oh... the error again.

The question is: Why is stopping the execution if it's only a warning? Can I set some settings to just proceed when it's a warning?

And how you debug this? I just don't know how to handle when things break like that... if I set to developer it works...

If you wanna see the code:

<?php
namespace Sgi\Override\Controller\Magento_Contact;

class Post extends \Magento\Contact\Controller\Index
{

    /**
     * Post user question
     *
     * @return void
     * @throws \Exception
     */
    public function execute()
    {
        $post = $this->getRequest()->getPostValue();
        if (!$post) {
            $this->_redirect('*/*/');
            return;
        }

        $this->inlineTranslation->suspend();
        try {
            $postObject = new \Magento\Framework\DataObject();
            $postObject->setData($post);

            $error = false;

            if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }
            if (\Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                $error = true;
            }
            if ($error) {
                throw new \Exception();
            }

        $setFrom = [
                    'name' => $post['name'],
                        'email' => $post['email'],
                        ];

            $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
            $transport = $this->_transportBuilder
                ->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))
                ->setTemplateOptions(
                    [
                        'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
                        'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                    ]
                )
                ->setTemplateVars(['data' => $postObject])
        ->setFrom($setFrom)
                ->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))
                ->setReplyTo($post['email'])
                ->getTransport();

            $transport->sendMessage();
            $this->inlineTranslation->resume();
            $this->messageManager->addSuccess(
                __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
            );
            $this->_redirect('contact-us');
            return;
        } catch (\Exception $e) {
            $this->inlineTranslation->resume();
            $this->messageManager->addError(
                __('We can\'t process your request right now. Sorry, that\'s all we know.')
            );
            $this->_redirect('contact-us');
            return;
        }
    }
}

And the report:

a:4:{i:0;s:163:"Warning: ltrim() expects parameter 1 to be string, object given in /home/magento-domain/public_html/vendor/magento/framework/Code/Generator/EntityAbstract.php on line 152";i:1;s:7045:"#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'ltrim() expects...', '/home/magento-domain/p...', 152, Array)
#1 /home/magento-domain/public_html/vendor/magento/framework/Code/Generator/EntityAbstract.php(152): ltrim(Object(Magento\Framework\ObjectManager\ObjectManager), '\\')
#2 /home/magento-domain/public_html/vendor/magento/framework/Code/Generator/EntityAbstract.php(81): Magento\Framework\Code\Generator\EntityAbstract->_getFullyQualifiedClassName(Object(Magento\Framework\ObjectManager\ObjectManager))
#3 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): Magento\Framework\Code\Generator\EntityAbstract->__construct(Object(Magento\Framework\ObjectManager\ObjectManager))
#4 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Framewo...', Array)
#5 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\\Framewo...', Array)
#6 /home/magento-domain/public_html/vendor/magento/framework/Code/Generator.php(136): Magento\Framework\ObjectManager\ObjectManager->create('Magento\\Framewo...', Array)
#7 /home/magento-domain/public_html/vendor/magento/framework/Code/Generator.php(110): Magento\Framework\Code\Generator->createGeneratorInstance('\\Magento\\Framew...', 'Sgi\\Override\\Co...', 'Sgi\\Override\\Co...')
#8 /home/magento-domain/public_html/vendor/magento/framework/Code/Generator/Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Sgi\\Override\\Co...')
#9 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Sgi\\Override\\Co...')
#10 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): spl_autoload_call('Sgi\\Override\\Co...')
#11 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Sgi\\Override\\Co...', Array)
#12 /home/magento-domain/public_html/vendor/magento/framework/ObjectManager/ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Sgi\\Override\\Co...', Array)
#13 /home/magento-domain/public_html/vendor/magento/framework/App/ActionFactory.php(40): Magento\Framework\ObjectManager\ObjectManager->create('Magento\\Contact...')
#14 /home/magento-domain/public_html/vendor/magento/framework/App/Router/Base.php(300): Magento\Framework\App\ActionFactory->create('Magento\\Contact...')
#15 /home/magento-domain/public_html/vendor/magento/framework/App/Router/Base.php(161): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array)
#16 /home/magento-domain/public_html/vendor/magento/framework/App/FrontController.php(50): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http))
#17 /home/magento-domain/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#18 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#19 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#20 /home/magento-domain/public_html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#21 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#22 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#23 /home/magento-domain/public_html/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#24 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#25 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#26 /home/magento-domain/public_html/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#27 /home/magento-domain/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#28 /home/magento-domain/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#29 /home/magento-domain/public_html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#30 /home/magento-domain/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#31 /home/magento-domain/public_html/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#32 /home/magento-domain/public_html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#33 /home/magento-domain/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#34 /home/magento-domain/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#35 {main}";s:3:"url";s:23:"/en/contact/index/post/";s:11:"script_name";s:10:"/index.php";}
  • Run rm -rf var/di/* it will solve issue. If needed run php bin/magento setup:di:compile – Ankit Shah Feb 21 '17 at 1:43
1

Run

rm -rf var/di/*

If needed run

rm -rf var/cache/* var/generation/* var/view_preprocessed/* pub/static/*
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex
php bin/magento cache:flush
  • Okay, WHAT is happening? I run rm -rf var/di/* and it worked fine, then I run php bin/magento deploy:mode:set production and it broke again. And running these commands one by one it's not solving (Well I thought the command that sets to production mode runs all these commands except cache flush and reindex)... what is going on? seems that I have to compile and after delete /di/ folder??? I'm freaking out – slayerbleast Feb 21 '17 at 8:31
  • Only this command works fine rm -rf var/di/* – Ankit Shah Feb 21 '17 at 8:32
  • Well... but I want to know why. So you are compiling the code, and then you delete the di folder? that makes no sense... – slayerbleast Feb 21 '17 at 22:27

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.