Skip to content

Commit ed9d3be

Browse files
author
Ébano Penha Andrello Lopes
committed
3.0.4: MAG-301: Fix for x-forwarded-for Magento bug
magento/magento2#7227 x_forwarded_for should be copied from quote, but quote does not have the field on database
1 parent 2f12636 commit ed9d3be

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Observer/Purchase.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Signifyd\Connect\Helper\ConfigHelper;
1616
use Signifyd\Connect\Model\CaseRetry;
1717
use Magento\Store\Model\StoreManagerInterface;
18+
use Magento\Framework\App\RequestInterface;
1819

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

70+
/**
71+
* @var RequestInterface
72+
*/
73+
protected $request;
74+
6975
/**
7076
* Purchase constructor.
7177
* @param LogHelper $logger
@@ -79,7 +85,8 @@ public function __construct(
7985
PurchaseHelper $helper,
8086
ConfigHelper $configHelper,
8187
ObjectManagerInterface $objectManagerInterface,
82-
StoreManagerInterface $storeManager = null
88+
StoreManagerInterface $storeManager = null,
89+
RequestInterface $request
8390
) {
8491
$this->logger = $logger;
8592
$this->helper = $helper;
@@ -88,6 +95,7 @@ public function __construct(
8895
$this->storeManager = empty($storeManager) ?
8996
$objectManagerInterface->get('Magento\Store\Model\StoreManagerInterface') :
9097
$storeManager;
98+
$this->request = $request;
9199
}
92100

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

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

115125
if (!empty($storeCode)) {
116126
$order->setData('origin_store_code', $storeCode);
117-
$order->save();
127+
$saveOrder = true;
128+
}
129+
}
130+
131+
// Fix for Magento bug https://github.com/magento/magento2/issues/7227
132+
// x_forwarded_for should be copied from quote, but quote does not have the field on database
133+
if (empty($order->getData('x_forwarded_for')) && is_object($this->request)) {
134+
$xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');
135+
136+
if (empty($xForwardIp) == false) {
137+
$order->setData('x_forwarded_for', $xForwardIp);
138+
$saveOrder = true;
118139
}
119140
}
120141

142+
if ($saveOrder) {
143+
$order->save();
144+
}
145+
121146
// Check if a payment is available for this order yet
122147
if ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
123148
return;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"php": ">=5.5.22"
88
},
99
"type": "magento2-module",
10-
"version": "3.0.3",
10+
"version": "3.0.4",
1111
"autoload": {
1212
"files": [
1313
"registration.php"

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
8-
<module name="Signifyd_Connect" setup_version="3.0.3">
8+
<module name="Signifyd_Connect" setup_version="3.0.4">
99
<sequence>
1010
<module name="Magento_Sales" />
1111
<module name="Magento_Payment" />

0 commit comments

Comments
 (0)