Skip to content

Commit

Permalink
Merge branch 'MAG-517' into 3.5.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	etc/module.xml
  • Loading branch information
ebanolopes committed Feb 5, 2020
2 parents 5566b8c + 6b6592a commit d179253
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 48 deletions.
121 changes: 121 additions & 0 deletions Observer/Debug/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* Copyright 2017 SIGNIFYD Inc. All rights reserved.
* See LICENSE.txt for license details.
*/

namespace Signifyd\Connect\Observer\Debug;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\UrlInterface;
use Signifyd\Connect\Logger\Debugger;
use Signifyd\Connect\Helper\ConfigHelper;

/**
* Observer for purchase event. Sends order data to Signifyd service
*/
class Order implements ObserverInterface
{
/**
* @var \Signifyd\Connect\Logger\Debugger
*/
protected $logger;

/**
* @var ConfigHelper
*/
protected $configHelper;

/**
* @var UrlInterface
*/
protected $url;

/**
* Order constructor.
* @param Debugger $logger
* @param ConfigHelper $configHelper
* @param UrlInterface $url
*/
public function __construct(
Debugger $logger,
ConfigHelper $configHelper,
UrlInterface $url
) {
$this->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) {
}
}
}
49 changes: 1 addition & 48 deletions Plugin/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_commit_after">
<observer name="onPurchase" instance="Signifyd\Connect\Observer\Purchase" />
<observer name="signifydDebugLogs" instance="Signifyd\Connect\Observer\Debug\Order" />
</event>

<event name="checkout_submit_all_after">
Expand Down

0 comments on commit d179253

Please sign in to comment.