-
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.
Merge pull request #1077 from magento-tsg/2.1.8-develop-pr14
[TSG] Backporting for 2.1 (pr14) (2.1.8)
- Loading branch information
Showing
20 changed files
with
622 additions
and
57 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
80 changes: 80 additions & 0 deletions
80
app/code/Magento/Sales/Observer/ConvertAdditionalInfoObserver.php
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Sales\Observer; | ||
|
||
use Magento\Framework\App\Area; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Sales\Api\Data\OrderPaymentInterface; | ||
use Magento\Sales\Model\ResourceModel\Order\Payment\Collection; | ||
|
||
/** | ||
* Class ConvertAdditionalInfo convert additional info from multidimensional array into single one for API calls. | ||
*/ | ||
class ConvertAdditionalInfoObserver implements ObserverInterface | ||
{ | ||
/** | ||
* Application state for identifying API calls. | ||
* | ||
* @var State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* ConvertAdditionalInfoObserver constructor. | ||
* @param State $state | ||
*/ | ||
public function __construct(State $state) | ||
{ | ||
$this->state = $state; | ||
} | ||
|
||
/** | ||
* Convert additional info from multidimensional array into single one for API calls. | ||
* | ||
* @param Observer $observer | ||
* @return void | ||
*/ | ||
public function execute(\Magento\Framework\Event\Observer $observer) | ||
{ | ||
/** @var Collection $paymentCollection */ | ||
$paymentCollection = $observer->getData('order_payment_collection'); | ||
$areaCode = $this->state->getAreaCode(); | ||
if ($areaCode == Area::AREA_WEBAPI_REST || $areaCode == Area::AREA_WEBAPI_SOAP) { | ||
foreach ($paymentCollection as $payment) { | ||
if (!empty($payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) { | ||
$additionalInfo = $this->convertAdditionalInfo( | ||
$payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION) | ||
); | ||
$payment->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Convert multidimensional additional information array to single. | ||
* | ||
* @param array $info | ||
* @return array | ||
*/ | ||
private function convertAdditionalInfo($info) | ||
{ | ||
$result = []; | ||
foreach ($info as $key => $item) { | ||
if (is_array($item)) { | ||
$result += $this->convertAdditionalInfo($item); | ||
unset($info[$key]); | ||
} else { | ||
$result[$key] = $item; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.