-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAddDataToOrdersGrid.php
57 lines (53 loc) · 1.91 KB
/
AddDataToOrdersGrid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Bdcrops\ExtendedOrdersGrid\Plugin;
/**
* Class AddDataToOrdersGrid
*/
class AddDataToOrdersGrid {
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* AddDataToOrdersGrid constructor.
*
* @param \Psr\Log\LoggerInterface $customLogger
* @param array $data
*/
public function __construct(
\Psr\Log\LoggerInterface $customLogger,
array $data = [] ) {
$this->logger = $customLogger;
}
/**
* @param \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject
* @param \Magento\Sales\Model\ResourceModel\Order\Grid\Collection $collection
* @param $requestName
* @return mixed
*/
public function afterGetReport($subject, $collection, $requestName) {
if ($requestName !== 'sales_order_grid_data_source') {
return $collection;
}
if ($collection->getMainTable() === $collection->getResource()->getTable('sales_order_grid')) {
try {
$orderAddressTableName = $collection->getResource()->getTable('sales_order_address');
$directoryCountryRegionTableName = $collection->getResource()->getTable('directory_country_region');
$collection->getSelect()->joinLeft(
['soa' => $orderAddressTableName],
'soa.parent_id = main_table.entity_id AND soa.address_type = \'shipping\'',
null
);
$collection->getSelect()->joinLeft(
['dcrt' => $directoryCountryRegionTableName],
'soa.region_id = dcrt.region_id',
['code']
);
} catch (\Zend_Db_Select_Exception $selectException) {
// Do nothing in that case
$this->logger->log(100, $selectException);
}
}
return $collection;
}
}