-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #7227: "x_forwarded_for" value is always empty in Order object
- Loading branch information
Showing
2 changed files
with
88 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,16 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface | |
*/ | ||
private $addressesToSync = []; | ||
|
||
/** | ||
* @var \Magento\Framework\App\RequestInterface | ||
*/ | ||
private $request; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kandy
Contributor
|
||
|
||
/** | ||
* @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress | ||
*/ | ||
private $remoteAddress; | ||
|
||
/** | ||
* @param EventManager $eventManager | ||
* @param QuoteValidator $quoteValidator | ||
|
@@ -169,6 +179,8 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface | |
* @param QuoteFactory $quoteFactory | ||
* @param \Magento\Quote\Model\QuoteIdMaskFactory|null $quoteIdMaskFactory | ||
* @param \Magento\Customer\Api\AddressRepositoryInterface|null $addressRepository | ||
* @param \Magento\Framework\App\RequestInterface|null $request | ||
* @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress | ||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||
*/ | ||
public function __construct( | ||
|
@@ -193,7 +205,9 @@ public function __construct( | |
\Magento\Customer\Api\AccountManagementInterface $accountManagement, | ||
\Magento\Quote\Model\QuoteFactory $quoteFactory, | ||
\Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory = null, | ||
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository = null | ||
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository = null, | ||
\Magento\Framework\App\RequestInterface $request = null, | ||
\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress = null | ||
) { | ||
$this->eventManager = $eventManager; | ||
$this->quoteValidator = $quoteValidator; | ||
|
@@ -219,6 +233,10 @@ public function __construct( | |
->get(\Magento\Quote\Model\QuoteIdMaskFactory::class); | ||
$this->addressRepository = $addressRepository ?: ObjectManager::getInstance() | ||
->get(\Magento\Customer\Api\AddressRepositoryInterface::class); | ||
$this->request = $request ?: ObjectManager::getInstance() | ||
->get(\Magento\Framework\App\RequestInterface::class); | ||
$this->remoteAddress = $remoteAddress ?: ObjectManager::getInstance() | ||
->get(\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class); | ||
} | ||
|
||
/** | ||
|
@@ -368,6 +386,14 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) | |
$quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); | ||
} | ||
|
||
$remoteAddress = $this->remoteAddress->getRemoteAddress(); | ||
if ($remoteAddress !== false) { | ||
$quote->setRemoteIp($remoteAddress); | ||
$quote->setXForwardedFor( | ||
$this->request->getServer('HTTP_X_FORWARDED_FOR') | ||
); | ||
} | ||
|
||
$this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]); | ||
|
||
$order = $this->submit($quote); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Keep proprieties
protected
making them private makes extending these classes a burden!