1

I'm facing a problem in which I have created an observer as follows:

<?php
namespace Magento\SamplePaymentGateway\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class ProcessGatewayRedirect extends ObserverInterface
{
    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    { 
        //die('order lllllllllllllllllllll');
        $orderId = $observer->getEvent()->getOrderIds();
        $base_url = $this->_storeManager->getStore()->getBaseUrl();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId[0]);
        $payment = $order->getPayment();


        $method = $payment->getMethodInstance();
        $methodTitle = $method->getTitle();

        $order_data= $order->getData();
        $status = $this->checkoutSession->getLastOrderStatus();

          $increment_id = $order_data['increment_id'];
          $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');
          $redirect->setRedirect($base_url.'custompayment/index/redirect/id/'.$increment_id.'');
          return;

    }
}

events.xml

<?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="sales_order_place_after">
       <observer name="process_gateway_redirect" instance="Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect" />
   </event>
</config>

Then when I run

php bin/magento setup:di:compile

command I get error as follows:

Fatal error: Class Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect cannot extend from interface Magento\Framework\Event\ObserverInterface in /var/www/html/m4/app/code/Magento/SamplePaymentGateway/Observer/ProcessGatewayRedirect.php on line 39

Fatal error: Class Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect cannot extend from interface Magento\Framework\Event\ObserverInterface in /var/www/html/m4/app/code/Magento/SamplePaymentGateway/Observer/ProcessGatewayRedirect.php on line 39 Segmentation fault (core dumped)

Line 39 in ProcessGatewayRedirect.php is the closing bracket of the observer class. I'm unable to figure out the real cause.

I doubt that my observer is not properly registered, so is there any fault in my code or is there any way we can list all the observers currently in our system?

  • You need to implement an interface not extend it. So it should be class ProcessGatewayRedirect implements ObserverInterface. – quickshiftin Dec 5 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.