Skip to content

Commit

Permalink
MC-42758: Shipment email shows tracking numbers from other shippings
Browse files Browse the repository at this point in the history
- fix
- add integration test
  • Loading branch information
o-dubovyk committed Jul 12, 2021
1 parent bf4cdad commit 0de4f96
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/* @var \Magento\Sales\Model\Order $_order */
$_order = $block->getOrder() ?>
<?php if ($_shipment && $_order) : ?>
<?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
<?php $trackCollection = $_shipment->getTracksCollection() ?>
<?php if ($trackCollection) : ?>
<br />
<table class="shipment-track">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,55 @@ public function testGetTracksCollection()
[$secondShipmentTrack->getEntityId()]
);
}

/**
* Check that getTracksCollection() returns only shipment related tracks.
*
* For the Block and Template responsible for sending email notification, when multiple items order
* has multiple shipments and every shipment has a separate tracking, shipment should contain
* only tracking info related to given shipment.
*
* @magentoDataFixture Magento/Sales/_files/order_with_two_order_items_with_simple_product.php
*/
public function testBlock()
{
$order = $this->getOrder('100000001');

$shipments = [];
foreach ($order->getItems() as $item) {
$items[$item->getId()] = $item->getQtyOrdered();
/** @var ShipmentTrackInterface $track */
$track = $this->objectManager->create(ShipmentTrackInterface::class);
$track->setNumber('Test Number')
->setTitle('Test Title')
->setCarrierCode('Test CODE');
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
$shipment = $this->objectManager->get(ShipmentFactory::class)
->create($order, $items);
$shipment->addTrack($track);
$this->shipmentRepository->save($shipment);
$shipments[] = $shipment;
}

// we extract only the latest shipment
$shipment = array_pop($shipments);

$block = $this->objectManager->create(
\Magento\Sales\Block\Order\Email\Shipment\Items::class,
[
'data' => [
'order' => $order,
'shipment' => $shipment,
]
]
);

$tracks = $block->getShipment()->getTracksCollection()->getItems();
$this->assertEquals(1, count($tracks),
'There should be only one Tracking item in collection');

$track = array_pop($tracks);
$this->assertEquals($shipment->getId(), $track->getParentId(),
'Check that the Tracking belongs to the Shipment');
}
}

0 comments on commit 0de4f96

Please sign in to comment.