46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
| <?php
 | |
| 
 | |
| namespace IpSupply\SyncOrder\Observer;
 | |
| 
 | |
| use Magento\Framework\Event\ObserverInterface;
 | |
| 
 | |
| class CheckOrderStatus implements ObserverInterface
 | |
| {
 | |
| 
 | |
|     protected $orderRepository;
 | |
|     protected $dir;
 | |
| 
 | |
|     public function __construct(
 | |
|         \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
 | |
|         \Magento\Framework\Filesystem\DirectoryList $dir,
 | |
|     ) {
 | |
|         $this->orderRepository = $orderRepository;
 | |
|         $this->dir = $dir;
 | |
|     }
 | |
| 
 | |
|     protected function _saveLog($content)
 | |
|     {
 | |
|         $file = $this->dir->getPath('log') . '/' . 'CheckOrderStatus.log';
 | |
| 
 | |
|         if (!file_exists($file)) {
 | |
|             $fh = fopen($file, 'w') or die("Can't create file");
 | |
|             fclose($fh);
 | |
|         }
 | |
|         $currentContent = file_get_contents($file);
 | |
|         $currentContent .= date("Y-m-d H:i:s") . ':';
 | |
|         $currentContent .= $content;
 | |
|         $currentContent .= "\n";
 | |
|         file_put_contents($file, $currentContent);
 | |
|     }
 | |
| 
 | |
|     public function execute(\Magento\Framework\Event\Observer $observer)
 | |
|     {
 | |
|         $order = $observer->getEvent()->getOrder();
 | |
| 
 | |
|         $order = [
 | |
|             'customer_id' => $order->getCustomerId(),
 | |
|             'status' => $order->getStatus(),
 | |
|         ];
 | |
|     }
 | |
| }
 |