Model observer file <?php namespace Exp\Test\Model\Observer; use Magento\Framework\Event\ObserverInterface; use Exception;
<?php
namespace Exp\Test\Model\Observer;
use Magento\Framework\Event\ObserverInterface;
use Exception;
class PaymentActive implements ObserverInterface {
public function __construct (
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_logger = $logger;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$this->testlog = $logger;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode();
$this->testlog->info($method->getCode());
if($method->getCode() == 'cashondelivery'){
$result->setData( 'is_available', false);
}
}
}