Skip to content

Commit

Permalink
[Backport] magento#8035 join extension attributes not added to orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarraban committed Jul 5, 2018
1 parent 8a0fd71 commit 032c82d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/code/Magento/Sales/Model/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Sales\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Sales\Model\ResourceModel\Order as Resource;
use Magento\Sales\Model\ResourceModel\Metadata;
use Magento\Sales\Model\Order\ShippingAssignmentBuilder;
Expand All @@ -16,6 +17,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;

/**
* Repository class for @see OrderInterface
Expand Down Expand Up @@ -43,6 +45,11 @@ class OrderRepository implements \Magento\Sales\Api\OrderRepositoryInterface
*/
private $shippingAssignmentBuilder;

/**
* @var JoinProcessorInterface
*/
private $joinProcessor;

/**
* OrderInterface[]
*
Expand All @@ -55,13 +62,17 @@ class OrderRepository implements \Magento\Sales\Api\OrderRepositoryInterface
*
* @param Metadata $metadata
* @param SearchResultFactory $searchResultFactory
* @param JoinProcessorInterface $joinProcessor
*/
public function __construct(
Metadata $metadata,
SearchResultFactory $searchResultFactory
SearchResultFactory $searchResultFactory,
JoinProcessorInterface $joinProcessor
) {
$this->metadata = $metadata;
$this->searchResultFactory = $searchResultFactory;
$this->joinProcessor = $joinProcessor
?: ObjectManager::getInstance()->get(JoinProcessorInterface::class);
}

/**
Expand Down Expand Up @@ -116,6 +127,7 @@ public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
);
}

$this->joinProcessor->process($searchResult);
$searchResult->setSearchCriteria($searchCriteria);
$searchResult->setCurPage($searchCriteria->getCurrentPage());
$searchResult->setPageSize($searchCriteria->getPageSize());
Expand Down Expand Up @@ -186,7 +198,7 @@ private function setShippingAssignments(OrderInterface $order)

/**
* Get the new OrderExtensionFactory for application code
*
*
* @return OrderExtensionFactory
* @deprecated
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@
</join>
</attribute>
</extension_attributes>
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
<attribute code="orderApiTestAttribute" type="Magento\User\Api\Data\UserInterface">
<join reference_table="admin_user"
join_on_field="store_id"
reference_field="user_id"
>
<field>firstname</field>
<field>lastname</field>
<field>email</field>
</attribute>
</extension_attributes>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,48 @@ public function testAutoGeneratedGetList()
$this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']);
}

/**
* Test get list of orders with extension attributes
*
* @magentoApiDataFixture Magneto/Sales/_files/order.php
*/
public function testGetOrderList()
{
$filter = $this->filterBuilder
->setField('increment_id')
->setValue('100000001')
->setConditionType('eq')
->create();
$this->searchBuilder->addFilters([$filter]);
$searchData = $this->searchBuilder->create()->__toArray();

$requestData = ['searchCriteria' => $searchData];
$restResourcePath = '/V1/orders/';
$soapService = 'salesOrderRepositoryV1';
$expectedExtensionAttributes = $this->getExpectedExtensionAttributes();

$serviceInfo = [
'rest' => [
'resourcePath' => $restResourcePath . '?' . http_build_query($requestData),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => $soapService,
'operation' => $soapService . 'GetList',
],
];
$searchResult = $this->_webApiCall($serviceInfo, $requestData);

$this->assertArrayHasKey('items', $searchResult);
$itemData = array_pop($searchResult['items']);
$this->assertArrayHasKey('extension_attributes', $itemData);
$this->assertArrayHasKey('order_api_test_attribute', $itemData['extension_attributes']);
$testAttribute = $itemData['extension_attributes']['order_api_test_attribute'];
$this->assertEquals($expectedExtensionAttributes['firstname'], $testAttribute['first_name']);
$this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute['last_name']);
$this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']);
}

/**
* Retrieve the admin user's information.
*
Expand Down

0 comments on commit 032c82d

Please sign in to comment.