I've already been able to add my column to the
sales_order_shipment_grid. Now it's time to join the data from another table so we can display it.
Some articles online suggest adding a join to the Grid resource model using something like:
<virtualType name="ShipmentGridAggregator"> <arguments> <argument name="joins" xsi:type="array"> <item name="my_table" xsi:type="array"> <item name="table" xsi:type="string">my_table</item> <item name="origin_column" xsi:type="string">their_column</item> <item name="target_column" xsi:type="string">my_column</item> </item> </argument> <argument name="columns" xsi:type="array"> <item name="my_column" xsi:type="string">my_table.my_other_column</item> </argument> </arguments> </virtualType>
The problem with this (as far as I can tell), is that this is deprecated in favor of using UIComponents and DataProviders. The
ShipmentGridAggregator is not used anywhere except for
Magento\Sales\Model\ResourceModel\GridPool, which in itself is not used for anything useful.
So, time to dig in deeper... The shipment grid uses a data source called
sales_order_view_shipment_grid_data_source this in turn is configured to use
Magento\Sales\Model\ResourceModel\Order\Shipment\Order\Grid\Collection. This class doesn't have an
$_eventPrefix so we can't use an observer to join our field.
We are able to inject a custom
FetchStrategyInterface into the collection listed above, but this doesn't seem to be its intended purpose. Will probably make it problematic with other modules that need to do something similar.
The current plan... Just do a before-plugin on
Magento\Sales\Model\ResourceModel\Order\Shipment\Order\Grid\Collection::load and add the join to
Anyone have any better ideas?