diff --git a/Observer/Debug/Order.php b/Observer/Debug/Order.php new file mode 100644 index 00000000..602a5eff --- /dev/null +++ b/Observer/Debug/Order.php @@ -0,0 +1,121 @@ +logger = $logger; + $this->configHelper = $configHelper; + $this->url = $url; + } + + public function execute(Observer $observer) + { + try { + /** @var $order \Magento\Sales\Model\Order */ + $order = $observer->getEvent()->getOrder(); + + $log = $this->configHelper->getConfigData('signifyd/logs/log', $order); + + // Log level 2 => debug + if ($log == 2) { + $state = $order->getState(); + $currentState = $order->getOrigData('state'); + + if ($state <> $currentState) { + $incrementId = $order->getIncrementId(); + + $this->logger->debug("Order {$incrementId} state change from {$currentState} to {$state}"); + $this->logger->debug("Request URL: {$this->url->getCurrentUrl()}"); + + $debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $debugBacktraceLog = []; + $nonMagentoModules = []; + + foreach ($debugBacktrace as $i => $step) { + $debugBacktraceLog[$i] = []; + $function = ''; + + if (isset($step['class'])) { + $function .= $step['class']; + + if ($step['class'] != \Signifyd\Connect\Plugin\Magento\Sales\Model\Order::class) { + list($vendor, $module, $class) = explode('\\', $step['class'], 3); + + if ($vendor != "Magento") { + $nonMagentoModules["{$vendor}\\{$module}"] = ''; + } + } + } + + if (isset($step['type'])) { + $function .= $step['type']; + } + + if (isset($step['function'])) { + $function .= $step['function']; + } + + $debugBacktraceLog[$i][] = "\t[{$i}] {$function}"; + + $file = isset($step['file']) ? str_replace(BP, '', $step['file']) : false; + + if ($file !== false) { + $debugBacktraceLog[$i][] = "line {$step['line']} on {$file}"; + } + + $debugBacktraceLog[$i] = implode(', ', $debugBacktraceLog[$i]); + } + + if (empty($nonMagentoModules) == false) { + $nonMagentoModulesList = implode(', ', array_keys($nonMagentoModules)); + $this->logger->debug("WARNING: non Magento modules found on backtrace: {$nonMagentoModulesList}"); + } + + $debugBacktraceLog = implode("\n", $debugBacktraceLog); + $this->logger->debug("Backtrace: \n{$debugBacktraceLog}\n\n"); + } + } + } catch (\Exception $e) { + } + } +} \ No newline at end of file diff --git a/Plugin/Magento/Sales/Model/Order.php b/Plugin/Magento/Sales/Model/Order.php index a7780d92..fa5b170d 100644 --- a/Plugin/Magento/Sales/Model/Order.php +++ b/Plugin/Magento/Sales/Model/Order.php @@ -54,55 +54,8 @@ public function beforeSetState(\Magento\Sales\Model\Order $subject, $state) $currentState = $subject->getState(); $incrementId = $subject->getIncrementId(); - $this->logger->debug("Order {$incrementId} state change from {$currentState} to {$state}"); + $this->logger->debug("setState on order {$incrementId} state change from {$currentState} to {$state}"); $this->logger->debug("Request URL: {$this->url->getCurrentUrl()}"); - - $debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - $debugBacktraceLog = []; - $nonMagentoModules = []; - - foreach ($debugBacktrace as $i => $step) { - $debugBacktraceLog[$i] = []; - $function = ''; - - if (isset($step['class'])) { - $function .= $step['class']; - - if ($step['class'] != \Signifyd\Connect\Plugin\Magento\Sales\Model\Order::class) { - list($vendor, $module, $class) = explode('\\', $step['class'], 3); - - if ($vendor != "Magento") { - $nonMagentoModules["{$vendor}\\{$module}"] = ''; - } - } - } - - if (isset($step['type'])) { - $function .= $step['type']; - } - - if (isset($step['function'])) { - $function .= $step['function']; - } - - $debugBacktraceLog[$i][] = "\t[{$i}] {$function}"; - - $file = isset($step['file']) ? str_replace(BP, '', $step['file']) : false; - - if ($file !== false) { - $debugBacktraceLog[$i][] = "line {$step['line']} on {$file}"; - } - - $debugBacktraceLog[$i] = implode(', ', $debugBacktraceLog[$i]); - } - - if (empty($nonMagentoModules) == false) { - $nonMagentoModulesList = implode(', ', array_keys($nonMagentoModules)); - $this->logger->debug("WARNING: non Magento modules found on backtrace: {$nonMagentoModulesList}"); - } - - $debugBacktraceLog = implode("\n", $debugBacktraceLog); - $this->logger->debug("Backtrace: \n{$debugBacktraceLog}\n\n"); } } catch (\Exception $e) { $this->logger->debug('Exception logging order state change: ' . $e->getMessage()); diff --git a/etc/events.xml b/etc/events.xml index 16b19b64..a4d8cbde 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -5,6 +5,7 @@ +