Skip to content

Uncaught Error: Call to a member function addItem() on array in app/code/Magento/Sales/Model/Order/Shipment.php #8022

Closed
@raisaev

Description

@raisaev

When adding a Track to a Shipment programmatically.

Preconditions

  1. Magento 2.1.1
  2. PHP 5.6.24

Steps to reproduce

  1. 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();
  1. Make a call
    $shipment->getTracks();

  2. 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

  1. 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

Component: SalesFixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions