From a78dae0ac5ab6db3d340a832651b4a77c1a1d18b Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Mon, 27 Dec 2021 15:17:20 +0100 Subject: [PATCH] fix: update grid columns from detail page --- Model/Sales/MagentoCollection.php | 17 +++++++++++------ Observer/NewShipment.php | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Model/Sales/MagentoCollection.php b/Model/Sales/MagentoCollection.php index b454ee50..7571a649 100755 --- a/Model/Sales/MagentoCollection.php +++ b/Model/Sales/MagentoCollection.php @@ -247,18 +247,23 @@ public function getHtmlForGridColumns($orderId) $areaObject = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_ADMINHTML); $areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE); } - $tracks = $this->getTracksCollectionByOrderId($orderId); + return $this->getHtmlForGridColumnsByTracks($this->getTracksCollectionByOrderId($orderId)); + } + + /** + * @param Order\Shipment\Track[]|\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection $tracks + * + * @return string[] + */ + public function getHtmlForGridColumnsByTracks($tracks): array + { $data = ['track_status' => [], 'track_number' => []]; $columnHtml = ['track_status' => '', 'track_number' => '']; - /** - * @var Order\Shipment $shipment - * @var Order\Shipment\Track $track - */ foreach ($tracks as $track) { // Set all Track data in array - if ($track['myparcel_status'] !== null) { + if (null !== $track['myparcel_status']) { $data['track_status'][] = __('status_' . $track['myparcel_status']); } if ($track['track_number']) { diff --git a/Observer/NewShipment.php b/Observer/NewShipment.php index 05bc535f..83a26606 100755 --- a/Observer/NewShipment.php +++ b/Observer/NewShipment.php @@ -140,9 +140,9 @@ private function setMagentoAndMyParcelTrack(Shipment $shipment) * * @throws \Exception */ - private function updateTrackGrid($shipment) + private function updateTrackGrid($shipment): void { - $aHtml = $this->orderCollection->getHtmlForGridColumns($shipment->getOrder()->getId()); + $aHtml = $this->orderCollection->getHtmlForGridColumnsByTracks($shipment->getTracksCollection()); $shipment->getOrder() ->setData('track_status', $aHtml['track_status']) ->setData('track_number', $aHtml['track_number'])