Skip to content

Commit

Permalink
3.0.4: MAG-301: Fix for x-forwarded-for Magento bug
Browse files Browse the repository at this point in the history
magento/magento2#7227
x_forwarded_for should be copied from quote, but quote does not have the
field on database
  • Loading branch information
Ébano Penha Andrello Lopes committed Dec 6, 2018
1 parent 2f12636 commit ed9d3be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions Observer/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Signifyd\Connect\Helper\ConfigHelper;
use Signifyd\Connect\Model\CaseRetry;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\RequestInterface;

/**
* Observer for purchase event. Sends order data to Signifyd service
Expand Down Expand Up @@ -66,6 +67,11 @@ class Purchase implements ObserverInterface
*/
protected $restrictedMethods = ['checkmo', 'banktransfer', 'purchaseorder', 'cashondelivery'];

/**
* @var RequestInterface
*/
protected $request;

/**
* Purchase constructor.
* @param LogHelper $logger
Expand All @@ -79,7 +85,8 @@ public function __construct(
PurchaseHelper $helper,
ConfigHelper $configHelper,
ObjectManagerInterface $objectManagerInterface,
StoreManagerInterface $storeManager = null
StoreManagerInterface $storeManager = null,
RequestInterface $request
) {
$this->logger = $logger;
$this->helper = $helper;
Expand All @@ -88,6 +95,7 @@ public function __construct(
$this->storeManager = empty($storeManager) ?
$objectManagerInterface->get('Magento\Store\Model\StoreManagerInterface') :
$storeManager;
$this->request = $request;
}

/**
Expand All @@ -108,16 +116,33 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true)
return;
}

$saveOrder = false;

// Saving store code to order, to know where the order is been created
if (empty($order->getData('origin_store_code')) && is_object($this->storeManager)) {
$storeCode = $this->storeManager->getStore($this->helper->isAdmin() ? 'admin' : true)->getCode();

if (!empty($storeCode)) {
$order->setData('origin_store_code', $storeCode);
$order->save();
$saveOrder = true;
}
}

// Fix for Magento bug https://github.com/magento/magento2/issues/7227
// x_forwarded_for should be copied from quote, but quote does not have the field on database
if (empty($order->getData('x_forwarded_for')) && is_object($this->request)) {
$xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');

if (empty($xForwardIp) == false) {
$order->setData('x_forwarded_for', $xForwardIp);
$saveOrder = true;
}
}

if ($saveOrder) {
$order->save();
}

// Check if a payment is available for this order yet
if ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
return;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=5.5.22"
},
"type": "magento2-module",
"version": "3.0.3",
"version": "3.0.4",
"autoload": {
"files": [
"registration.php"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Signifyd_Connect" setup_version="3.0.3">
<module name="Signifyd_Connect" setup_version="3.0.4">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit ed9d3be

Please sign in to comment.