Skip to content

Commit

Permalink
Merge pull request #13 from snowio/feature/add-get-list-plugin
Browse files Browse the repository at this point in the history
Add feature to GetList
  • Loading branch information
Alexander Wanyoike authored Jan 16, 2020
2 parents 539b3de + 4ac20a5 commit 6e38450
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Plugin/OrderRepositoryPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace SnowIO\ExtendedSalesRepositories\Plugin;

use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\Data\OrderSearchResultInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionFactory;

Expand All @@ -19,12 +20,24 @@ public function __construct(OrderPaymentExtensionFactory $orderPaymentExtensionF
* 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)
public function afterGet(OrderRepositoryInterface $subject, OrderInterface $order)
{
return $this->applyAttributesToOrderItem($order);
}

public function afterGetList(OrderRepositoryInterface $subject, OrderSearchResultInterface $orders)
{
foreach ($orders->getItems() as $order) {
$this->applyAttributesToOrderItem($order);
}
return $orders;
}

private function applyAttributesToOrderItem(OrderInterface $order): OrderInterface
{
$payment = $order->getPayment();
$additionalInformation = $payment->getAdditionalInformation();
$additionalInformationJson = json_encode($additionalInformation);

$extensionAttributes = $payment->getExtensionAttributes();
if (null === $extensionAttributes) {
$extensionAttributes = $this->orderPaymentExtensionFactory->create();
Expand All @@ -37,6 +50,5 @@ public function afterGet(OrderRepositoryInterface $orderRepository, OrderInterfa
}

return $order;

}
}
}

0 comments on commit 6e38450

Please sign in to comment.