Skip to content

Commit 0de4f96

Browse files
committed
MC-42758: Shipment email shows tracking numbers from other shippings
- fix - add integration test
1 parent bf4cdad commit 0de4f96

File tree

2 files changed

+52
-1
lines changed
  • app/code/Magento/Sales/view/frontend/templates/email/shipment
  • dev/tests/integration/testsuite/Magento/Sales/Model/Order

2 files changed

+52
-1
lines changed

app/code/Magento/Sales/view/frontend/templates/email/shipment/track.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/* @var \Magento\Sales\Model\Order $_order */
1111
$_order = $block->getOrder() ?>
1212
<?php if ($_shipment && $_order) : ?>
13-
<?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
13+
<?php $trackCollection = $_shipment->getTracksCollection() ?>
1414
<?php if ($trackCollection) : ?>
1515
<br />
1616
<table class="shipment-track">

dev/tests/integration/testsuite/Magento/Sales/Model/Order/ShipmentTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,55 @@ public function testGetTracksCollection()
202202
[$secondShipmentTrack->getEntityId()]
203203
);
204204
}
205+
206+
/**
207+
* Check that getTracksCollection() returns only shipment related tracks.
208+
*
209+
* For the Block and Template responsible for sending email notification, when multiple items order
210+
* has multiple shipments and every shipment has a separate tracking, shipment should contain
211+
* only tracking info related to given shipment.
212+
*
213+
* @magentoDataFixture Magento/Sales/_files/order_with_two_order_items_with_simple_product.php
214+
*/
215+
public function testBlock()
216+
{
217+
$order = $this->getOrder('100000001');
218+
219+
$shipments = [];
220+
foreach ($order->getItems() as $item) {
221+
$items[$item->getId()] = $item->getQtyOrdered();
222+
/** @var ShipmentTrackInterface $track */
223+
$track = $this->objectManager->create(ShipmentTrackInterface::class);
224+
$track->setNumber('Test Number')
225+
->setTitle('Test Title')
226+
->setCarrierCode('Test CODE');
227+
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
228+
$shipment = $this->objectManager->get(ShipmentFactory::class)
229+
->create($order, $items);
230+
$shipment->addTrack($track);
231+
$this->shipmentRepository->save($shipment);
232+
$shipments[] = $shipment;
233+
}
234+
235+
// we extract only the latest shipment
236+
$shipment = array_pop($shipments);
237+
238+
$block = $this->objectManager->create(
239+
\Magento\Sales\Block\Order\Email\Shipment\Items::class,
240+
[
241+
'data' => [
242+
'order' => $order,
243+
'shipment' => $shipment,
244+
]
245+
]
246+
);
247+
248+
$tracks = $block->getShipment()->getTracksCollection()->getItems();
249+
$this->assertEquals(1, count($tracks),
250+
'There should be only one Tracking item in collection');
251+
252+
$track = array_pop($tracks);
253+
$this->assertEquals($shipment->getId(), $track->getParentId(),
254+
'Check that the Tracking belongs to the Shipment');
255+
}
205256
}

0 commit comments

Comments
 (0)