Closed
Description
When adding a Track to a Shipment programmatically.
Preconditions
- Magento 2.1.1
- PHP 5.6.24
Steps to reproduce
- Load or create a Shipment model
/** @var $shipment \Magento\Sales\Model\Order\Shipment */
$shipmentCollection = $this->_objectManager->get(
'Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory'
)->create();
$shipment = $shipmentCollection->getFirstItem();
-
Make a call
$shipment->getTracks();
-
Create a Track model and try to add it to the Shipment
/** @var $track \Magento\Sales\Model\Order\Shipment\Track */
$track = $this->_objectManager->get(
'Magento\Sales\Model\Order\Shipment\TrackFactory'
)->create();
$track->setNumber('Test Number')
->setTitle('Test Title')
->setCarrierCode('Test CODE');
$shipment->addTrack($track)->save();
Expected result
- Successfull save
Actual result
You will receive an error Call to a member function addItem() on array because the method getTracksCollection() in Shipment model will return an array instead of Collection Object.
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release