Skip to content
Snippets Groups Projects
Select Git revision
  • d12b0aff4c3f1e5d03a4a4737230b0317e67a07f
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

ConfigChangeObserver.php

Blame
  • ConfigChangeObserver.php 1.35 KiB
    <?php
    
    namespace BobGroup\BobGo\Observer;
    
    use Magento\Framework\Event\Observer;
    use Magento\Framework\Event\ObserverInterface;
    use Magento\Framework\Message\ManagerInterface;
    use Psr\Log\LoggerInterface;
    use BobGroup\BobGo\Model\Carrier\BobGo;
    
    class ConfigChangeObserver implements ObserverInterface
    {
        protected $bobGo;
        protected $logger;
        protected $messageManager;
    
        public function __construct(
            BobGo $bobGo,
            LoggerInterface $logger,
            ManagerInterface $messageManager
        ) {
            $this->bobGo = $bobGo;
            $this->logger = $logger;
            $this->messageManager = $messageManager;
        }
    
        public function execute(Observer $observer)
        {
            $changedPaths = $observer->getEvent()->getData('changed_paths');
    
            if (is_array($changedPaths) && in_array('carriers/bobgo/active', $changedPaths)) {
    
                if ($this->bobGo->isActive()) {
                    $result = $this->bobGo->triggerRatesTest();
    
                    if ($result !== false) {
                        $this->messageManager->addSuccessMessage(__('Bob Go rates at checkout test is successful.'));
                    } else {
                        $this->messageManager->addErrorMessage(__('Bob Go rates at checkout test failed. Please visit https://www.bobgo.co.za/ and enable this channel for rates at checkout.'));
                    }
                }
            }
        }
    
    }