Set Join in SearchCriteria select
-
08-01-2021 - |
Question
I need to override the get orders list API call, and set a join with my custom table, but without loose the SearchCriteria terms, is this possible?
Current Code:
(I've created a plugin in Magento\Sales\Api\OrderRepositoryInterface
inside webapi_rest folder.)
public function aroundGetList
(
\Magento\Sales\Api\OrderRepositoryInterface $subject,
callable $proceed,
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
){
$searchResult = $this->searchResultFactory->create();
$this->collectionProcessor->process($searchCriteria, $searchResult);
$searchResult->setSearchCriteria($searchCriteria);
foreach ($searchResult->getItems() as $order) {
$this->setShippingAssignments($order);
}
return $searchResult;
}
Solution
I solve this situation as following:
$searchResult->getSelect()->joinLeft(
array('my_table'=>'myAlias'),
'main_table.entity_id = myAlias.id',
[]
);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange