-
Notifications
You must be signed in to change notification settings - Fork 3
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 #4 from snowio/fix/additional-information-webapi-r…
…esult Fix/additional information webapi result
- Loading branch information
Showing
10 changed files
with
68 additions
and
207 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
<?php | ||
namespace SnowIO\ExtendedSalesRepositories\Plugin; | ||
|
||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\Data\OrderPaymentExtensionFactory; | ||
|
||
class OrderRepositoryPlugin | ||
{ | ||
private $orderPaymentExtensionFactory; | ||
|
||
|
||
public function __construct(OrderPaymentExtensionFactory $orderPaymentExtensionFactory) | ||
{ | ||
$this->orderPaymentExtensionFactory = $orderPaymentExtensionFactory; | ||
} | ||
|
||
/** | ||
* Unset additional information to avoid web services being broken by nested array | ||
* and add the additional information as a json encoded string to an extension attribute. | ||
*/ | ||
public function afterGet(OrderRepositoryInterface $orderRepository, OrderInterface $order) | ||
{ | ||
$payment = $order->getPayment(); | ||
$additionalInformation = $payment->getAdditionalInformation(); | ||
$additionalInformationJson = json_encode($additionalInformation); | ||
|
||
$extensionAttributes = $payment->getExtensionAttributes(); | ||
if (null === $extensionAttributes) { | ||
$extensionAttributes = $this->orderPaymentExtensionFactory->create(); | ||
} | ||
$extensionAttributes->setAdditionalInformationJson($additionalInformationJson); | ||
$payment->setExtensionAttributes($extensionAttributes); | ||
|
||
if (method_exists($payment, 'unsAdditionalInformation')) { | ||
$payment->unsAdditionalInformation(); | ||
} | ||
|
||
return $order; | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference | ||
for="SnowIO\ExtendedSalesRepositories\Api\Data\AdditionalInformationFieldInterface" | ||
type="SnowIO\ExtendedSalesRepositories\Model\AdditionalInformationField" /> | ||
for="SnowIO\ExtendedSalesRepositories\Api\Data\AdditionalInformationFieldInterface" | ||
type="SnowIO\ExtendedSalesRepositories\Model\AdditionalInformationField" /> | ||
|
||
<preference | ||
for="SnowIO\ExtendedSalesRepositories\Api\ShipOrderByIncrementIdInterface" | ||
type="SnowIO\ExtendedSalesRepositories\Model\ShipOrderByIncrementId" /> | ||
|
||
<type name="Magento\Sales\Api\OrderPaymentRepositoryInterface"> | ||
<plugin name="OrderPaymentRepositoryExtensionPlugin" type="SnowIO\ExtendedSalesRepositories\Plugin\OrderPaymentRepositoryExtensionPlugin" disabled="false" /> | ||
</type> | ||
<type name="Magento\Sales\Api\OrderRepositoryInterface"> | ||
<plugin name="OrderRepositoryExtensionPlugin" type="SnowIO\ExtendedSalesRepositories\Plugin\OrderRepositoryExtensionPlugin" disabled="false" /> | ||
<plugin name="processAdditionalInformation" type="SnowIO\ExtendedSalesRepositories\Plugin\OrderRepositoryPlugin" disabled="true" /> | ||
</type> | ||
|
||
</config> |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> | ||
<extension_attributes for="Magento\Sales\Api\Data\OrderPaymentInterface"> | ||
<attribute code="AdditionalInformation" type="SnowIO\ExtendedSalesRepositories\Api\Data\AdditionalInformationFieldInterface[]" /> | ||
</extension_attributes> | ||
|
||
<extension_attributes for="Magento\Sales\Api\Data\ShipmentInterface"> | ||
<attribute code="order_increment_id" type="string" /> | ||
</extension_attributes> | ||
|
||
<extension_attributes for="Magento\Sales\Api\Data\OrderPaymentInterface"> | ||
<attribute code="additional_information_json" type="string" /> | ||
</extension_attributes> | ||
|
||
|
||
</config> |
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,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<type name="Magento\Sales\Api\OrderRepositoryInterface"> | ||
<plugin name="processAdditionalInformation" disabled="false"/> | ||
</type> | ||
|
||
</config> |
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,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<type name="Magento\Sales\Api\OrderRepositoryInterface"> | ||
<plugin name="processAdditionalInformation" disabled="false" /> | ||
</type> | ||
|
||
</config> |