0

I have to convert (translate) these two models from Magento 1 to Magento 2: Mage::getModel('sales/order_shipment_api') and Mage::getModel('sales/order_shipment') Where are they, and how can I get them using object manager? I need to access these methods(their substitutes) in Magento 2:

Mage::getModel('sales/order_shipment_api')->create($a, $b, 'shipment', false, 1);
Mage::getModel('sales/order_shipment_api')->addTrack($a, 'custom', $b, $c);
Mage::getModel('sales/order_shipment')->load($shipmentId);
3
  • Which function u want to use for both of them?
    – Jackson
    Commented Mar 24, 2017 at 2:50
  • Mage::getModel('sales/order_shipment_api')->create($a, $b, 'shipment', false, 1); Mage::getModel('sales/order_shipment_api')->addTrack($a, 'custom', $b, $c); Mage::getModel('sales/order_shipment')->load($shipmentId); Commented Mar 24, 2017 at 8:37
  • $shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId); for load shipment id Commented Mar 24, 2017 at 8:57

1 Answer 1

1

[1]

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //instance of\Magento\Framework\App\ObjectManager
$shipment   = $_objectManager->get('\Magento\Sales\Api\Data\ShipmentInterface');
$shipment->addTrack();

Reference file magento\vendor\magento\module-sales\Model\Order\ShipmentFactory.php

[2]

$shipment = $_objectManager->create('Magento\Sales\Model\Order\Shi‌​pment')->load($shipm‌​entId); 
1
  • The $objectManager->create('Magento\Sales\Model\Order\Shi‌​pment') method is used to create the factory object, but it is not the same ->create method to create the shipment as in Magento 1: Mage::getModel('sales/order_shipment_api')->create Commented Mar 27, 2017 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.