Skip to content

Commit

Permalink
Merge pull request #4 from snowio/fix/additional-information-webapi-r…
Browse files Browse the repository at this point in the history
…esult

Fix/additional information webapi result
  • Loading branch information
joshdifabio authored Dec 12, 2016
2 parents 10b1f41 + 1e10c99 commit 685d220
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 207 deletions.
35 changes: 0 additions & 35 deletions Api/Data/AdditionalInformationFieldInterface.php

This file was deleted.

81 changes: 0 additions & 81 deletions Model/AdditionalInformationField.php

This file was deleted.

32 changes: 0 additions & 32 deletions Model/AdditionalPaymentInformationExtender.php

This file was deleted.

24 changes: 0 additions & 24 deletions Plugin/OrderPaymentRepositoryExtensionPlugin.php

This file was deleted.

25 changes: 0 additions & 25 deletions Plugin/OrderRepositoryExtensionPlugin.php

This file was deleted.

42 changes: 42 additions & 0 deletions Plugin/OrderRepositoryPlugin.php
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;

}
}
10 changes: 4 additions & 6 deletions etc/di.xml
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>
10 changes: 6 additions & 4 deletions etc/extension_attributes.xml
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>
8 changes: 8 additions & 0 deletions etc/webapi_rest/di.xml
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>
8 changes: 8 additions & 0 deletions etc/webapi_soap/di.xml
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>

0 comments on commit 685d220

Please sign in to comment.