0

I created a module in order to save order data to a custom table:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action">
        <observer name="order_place_navision" instance="MyVendor\SalesOrderSync\Observer\SaveOrder"/>
    </event>
</config>

Observer/SaveOrder.php:

<?php

namespace MyVendor\SalesOrderSync\Observer;

use Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\App\Bootstrap;

class SaveOrder implements ObserverInterface
{
    private $logger;
    private $state;

    public function __construct(
        \Magento\Framework\View\Element\Context $context,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\App\State $state
    ) {
        $this->_layout = $context->getLayout();
        $this->_request = $context->getRequest();
        $this->logger = $logger;
        $this->_state = $state;

        try {
            $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            // nothing to do
        }

    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {

        $bootstrap = Bootstrap::create(BP, $_SERVER);
        $objectManager = $bootstrap->getObjectManager();
        $state = $objectManager->get('Magento\Framework\App\State');
        $state->setAreaCode('frontend');
        $objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
        $date = $objDate->gmtDate();

        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $connection = $resource->getConnection();
        $orderId = $observer->getEvent()->getOrderIds()[0];

        $sql = "INSERT INTO custom_sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
            $orderId .
            ", '" .
            "0" .
            "', '" .
            $date .
            "')" ;
        $connection->query($sql);

    }
}

But I get this error when I complete an order:

1 exception(s):
Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Captcha\Model\Checkout\ConfigProvider

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Captcha\Model\Checkout\ConfigProvider
<pre>#1 Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\Captcha\...') called at [vendor/magento/framework/ObjectManager/Factory/Compiled.php:150]
#2 Magento\Framework\ObjectManager\Factory\Compiled->get('Magento\Captcha\...') called at [vendor/magento/framework/ObjectManager/Factory/Compiled.php:79]
#3 Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\Captcha\...') called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]
#4 Magento\Framework\ObjectManager\ObjectManager->get('Magento\Captcha\...') called at [vendor/magento/framework/Interception/PluginList/PluginList.php:250]
#5 Magento\Framework\Interception\PluginList\PluginList->getPlugin('Magento\Checkout...', 'login_captcha') called at [vendor/magento/framework/Interception/Interceptor.php:144]
#6 Magento\Checkout\Block\Cart\Sidebar\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#7 Magento\Checkout\Block\Cart\Sidebar\Interceptor->___callPlugins('getConfig', array(), array(array('customer_cart', 'login_captcha'))) called at [generated/code/Magento/Checkout/Block/Cart/Sidebar/Interceptor.php:26]
#8 Magento\Checkout\Block\Cart\Sidebar\Interceptor->getConfig() called at [app/design/frontend/Smartwave/porto/Magento_Checkout/templates/cart/minicart.phtml:45]
#9 include('/var/www/html/ap...') called at [vendor/magento/framework/View/TemplateEngine/Php.php:59]
#10 Magento\Framework\View\TemplateEngine\Php->render(&Magento\Checkout\Block\Cart\Sidebar\Interceptor#0000000012d1f258000000005dbf9a65#, '/var/www/html/ap...', array()) called at [vendor/magento/framework/View/Element/Template.php:271]
#11 Magento\Framework\View\Element\Template->fetchView('/var/www/html/ap...') called at [vendor/magento/framework/View/Element/Template.php:301]
#12 Magento\Framework\View\Element\Template->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1094]
#13 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1098]
#14 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:671]
#15 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:557]
#16 Magento\Framework\View\Layout->_renderBlock('minicart') called at [vendor/magento/framework/View/Layout.php:533]
#17 Magento\Framework\View\Layout->renderNonCachedElement('minicart') called at [vendor/magento/framework/View/Layout.php:488]
#18 Magento\Framework\View\Layout->renderElement('minicart', true) called at [vendor/magento/framework/View/Element/AbstractBlock.php:518]
#19 Magento\Framework\View\Element\AbstractBlock->getChildHtml('minicart')
#20 call_user_func_array(array(&Smartwave\Porto\Block\Template#0000000012d1f267000000005dbf9a65#, 'getChildHtml'), array('minicart')) called at [vendor/magento/framework/View/TemplateEngine/Php.php:82]
#21 Magento\Framework\View\TemplateEngine\Php->__call('getChildHtml', array('minicart')) called at [app/design/frontend/Smartwave/porto/Smartwave_Porto/templates/html/header.phtml:269]
#22 include('/var/www/html/ap...') called at [vendor/magento/framework/View/TemplateEngine/Php.php:59]
#23 Magento\Framework\View\TemplateEngine\Php->render(&Smartwave\Porto\Block\Template#0000000012d1f267000000005dbf9a65#, '/var/www/html/ap...', array()) called at [vendor/magento/framework/View/Element/Template.php:271]
#24 Magento\Framework\View\Element\Template->fetchView('/var/www/html/ap...') called at [vendor/magento/framework/View/Element/Template.php:301]
#25 Magento\Framework\View\Element\Template->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1094]
#26 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1098]
#27 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:671]
#28 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:557]
#29 Magento\Framework\View\Layout->_renderBlock('porto_header') called at [vendor/magento/framework/View/Layout.php:533]
#30 Magento\Framework\View\Layout->renderNonCachedElement('porto_header') called at [vendor/magento/framework/View/Layout.php:488]
#31 Magento\Framework\View\Layout->renderElement('porto_header', false) called at [vendor/magento/framework/View/Layout.php:585]
#32 Magento\Framework\View\Layout->_renderContainer('page.wrapper', false) called at [vendor/magento/framework/View/Layout.php:535]
#33 Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper') called at [vendor/magento/framework/View/Layout.php:488]
#34 Magento\Framework\View\Layout->renderElement('page.wrapper', false) called at [vendor/magento/framework/View/Layout.php:585]
#35 Magento\Framework\View\Layout->_renderContainer('root', false) called at [vendor/magento/framework/View/Layout.php:535]
#36 Magento\Framework\View\Layout->renderNonCachedElement('root') called at [vendor/magento/framework/View/Layout.php:488]
#37 Magento\Framework\View\Layout->renderElement('root') called at [vendor/magento/framework/View/Layout.php:954]
#38 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#39 Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', array()) called at [vendor/magento/framework/Interception/Interceptor.php:138]
#40 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#41 Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', array(), array(array('layout-model-cac...'))) called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:39]
#42 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:258]
#43 Magento\Framework\View\Result\Page->render(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#) called at [vendor/magento/framework/View/Result/Layout.php:171]
#44 Magento\Framework\View\Result\Layout->renderResult(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#) called at [vendor/magento/framework/Interception/Interceptor.php:58]
#45 Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', array(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#)) called at [vendor/magento/framework/Interception/Interceptor.php:138]
#46 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#) called at [vendor/magento/framework/Interception/Interceptor.php:153]
#47 Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', array(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#), array(array('result-messages', 'result-builtin-c...', 'result-varnish-c...'))) called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:39]
#48 Magento\Framework\View\Result\Page\Interceptor->renderResult(&Magento\Framework\App\Response\Http\Interceptor#0000000012d1f40e000000005dbf9a65#) called at [vendor/magento/framework/App/Http.php:141]
#49 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.php:261]
#50 Magento\Framework\App\Bootstrap->run(&Magento\Framework\App\Http\Interceptor#0000000012d1f408000000005dbf9a65#) called at [index.php:39]
</pre>

Any idea in order to solve it?

0

Try to remove generation folder or in version 2.2 remove the generated folder.

rm -rf generated/

flush the cache. It should work then. its because the interceptor file needs to be re-created or refresh.

I hope its working to you.

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.