Custom rest api event observer confliction Magento2

Custom rest api event observer confliction Magento2

  • By admin
  • Magento 2
  • Comments Off on Custom rest api event observer confliction Magento2

Custom rest api event observer confliction Magento2

Custom rest api we need to define event and plugins under webapi_rest folder.
In this way it will not conflict default features.
Vendor/Module/etc/webapi_rest/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_model_service_quote_submit_before">
<observer instance="vendor\module\Observer\Order\Observerclass" name="events_change"/>
</event>
</config>
namespace vendor\module\Observer\Order;

use Magento\Quote\Model\QuoteRepository;
use Psr\Log\LoggerInterface;

class Observerclass implements \Magento\Framework\Event\ObserverInterface
{

protected $quoteRepository;

protected $logger;

public function __construct(
QuoteRepository $quoteRepository,
LoggerInterface $logger
) {
$this->logger = $logger;
$this->quoteRepository = $quoteRepository;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$order = $observer->getData('order');

if($order)
{
$order->setCanSendNewEmailFlag(false);
}

} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
return $this;
}
}