15
15
use Signifyd \Connect \Helper \ConfigHelper ;
16
16
use Signifyd \Connect \Model \CaseRetry ;
17
17
use Magento \Store \Model \StoreManagerInterface ;
18
+ use Magento \Framework \App \RequestInterface ;
18
19
19
20
/**
20
21
* Observer for purchase event. Sends order data to Signifyd service
@@ -66,6 +67,11 @@ class Purchase implements ObserverInterface
66
67
*/
67
68
protected $ restrictedMethods = ['checkmo ' , 'banktransfer ' , 'purchaseorder ' , 'cashondelivery ' ];
68
69
70
+ /**
71
+ * @var RequestInterface
72
+ */
73
+ protected $ request ;
74
+
69
75
/**
70
76
* Purchase constructor.
71
77
* @param LogHelper $logger
@@ -79,7 +85,8 @@ public function __construct(
79
85
PurchaseHelper $ helper ,
80
86
ConfigHelper $ configHelper ,
81
87
ObjectManagerInterface $ objectManagerInterface ,
82
- StoreManagerInterface $ storeManager = null
88
+ StoreManagerInterface $ storeManager = null ,
89
+ RequestInterface $ request
83
90
) {
84
91
$ this ->logger = $ logger ;
85
92
$ this ->helper = $ helper ;
@@ -88,6 +95,7 @@ public function __construct(
88
95
$ this ->storeManager = empty ($ storeManager ) ?
89
96
$ objectManagerInterface ->get ('Magento\Store\Model\StoreManagerInterface ' ) :
90
97
$ storeManager ;
98
+ $ this ->request = $ request ;
91
99
}
92
100
93
101
/**
@@ -108,16 +116,33 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true)
108
116
return ;
109
117
}
110
118
119
+ $ saveOrder = false ;
120
+
111
121
// Saving store code to order, to know where the order is been created
112
122
if (empty ($ order ->getData ('origin_store_code ' )) && is_object ($ this ->storeManager )) {
113
123
$ storeCode = $ this ->storeManager ->getStore ($ this ->helper ->isAdmin () ? 'admin ' : true )->getCode ();
114
124
115
125
if (!empty ($ storeCode )) {
116
126
$ 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 ;
118
139
}
119
140
}
120
141
142
+ if ($ saveOrder ) {
143
+ $ order ->save ();
144
+ }
145
+
121
146
// Check if a payment is available for this order yet
122
147
if ($ order ->getState () == \Magento \Sales \Model \Order::STATE_PENDING_PAYMENT ) {
123
148
return ;
0 commit comments