How do i create a shipment class object in magento 2?Create custom module to modify...

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

What does "Puller Prush Person" mean?

Alternative to sending password over mail?

Did Shadowfax go to Valinor?

Theorems that impeded progress

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Why can't we play rap on piano?

What does the "remote control" for a QF-4 look like?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Roll the carpet

Can a monk's single staff be considered dual wielded, as per the Dual Wielder feat?

How much RAM could one put in a typical 80386 setup?

What's that red-plus icon near a text?

Does object always see its latest internal state irrespective of thread?

NMaximize is not converging to a solution

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

Mortgage Pre-approval / Loan - Apply Alone or with Fiancée?

Is it legal for company to use my work email to pretend I still work there?

Why is consensus so controversial in Britain?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

dbcc cleantable batch size explanation

DC-DC converter from low voltage at high current, to high voltage at low current

"You are your self first supporter", a more proper way to say it



How do i create a shipment class object in magento 2?


Create custom module to modify sales/order/shipment/api.phpUnit Test for overwrite collection class in magento2Programatically add tracking to shipment - Mage_Api_Model_Resource_Abstract->_fault('not_exists')main.CRITICAL: Plugin class doesn't existHow to change save path of PDF files in magento 2Magento 2.1.6 Cannot save shipmentMagento offline custom Payment method with drop down listHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?Adding tracking number to existing orders from CSV file Programmatically in Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















i am trying to get tracking from csv and load to magento 2 order programmatically.
i grabbed the create shipment & add tracking code from here https://www.scommerce-mage.com/blog/magento-2-how-to-create-shipment-programatically.html, and add an execute function (line 122) to load data from csv. but i'm not sure how to create an shipment object (line 175).



<?php
$file = fopen('track.csv', 'r', '"'); // set path to the CSV file
if ($file !== false)
{
require __DIR__ . '/app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('adminhtml');
// add logging capability
$writer = new ZendLogWriterStream(BP . '/var/log/import-update.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

class ShipmentObject{
/*There are two main functions
prepareShipment of MagentoSalesModelOrderShipmentFactory class which prepare invoice and
addObject of MagentoFrameworkDBTransactionFactory class which helps to create shipment and associate the shipment with original order in Magento 2.
*/

/**
* @var MagentoSalesModelOrderShipmentTrackFactory
*/
protected $_shipmentTrackFactory;

/**
* @var MagentoSalesModelOrderShipmentFactory
*/
protected $_shipmentFactory;

/**
* @var MagentoFrameworkDBTransactionFactory
*/
protected $_transactionFactory;

/**
* @var MagentoSalesApiOrderRepositoryInterface
*/
protected $_orderRepository;

/**
* @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
* @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
* @param MagentoFrameworkDBTransactionFactory $transactionFactory
* @param MagentoSalesApiOrderRepositoryInterface $orderRepository
*/
public function __construct(
MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory,
MagentoSalesModelOrderShipmentFactory $shipmentFactory,
MagentoFrameworkDBTransactionFactory $transactionFactory,
MagentoSalesApiOrderRepositoryInterface $orderRepository
) {
$this->_shipmentTrackFactory = $shipmentTrackFactory;
$this->_shipmentFactory = $shipmentFactory;
$this->_transactionFactory = $transactionFactory;
$this->_orderRepository = $orderRepository;
}

/**
* @param int $orderId
* @param string $trackingNumber
* @return MagentoSalesModelShipment $shipment
*/
protected function createShipment($orderId, $trackingNumber)
{
try {
$order = $this->_orderRepository->get($orderId);
if ($order){
$data = array(array(
'carrier_code' => $order->getShippingMethod(), //'carrier_code' => 'fedex', // need to lower case
'title' => $order->getShippingDescription(), //'title' => 'Federal Express', // how to set here 'Federal Express' or 'United Parcel Service'
'number' => $trackingNumber, //$trackingnumber,
));

$shipment = $this->prepareShipment($order, $data);
if ($shipment) {
$order->setIsInProcess(true);
$order->addStatusHistoryComment('Automatically SHIPPED', false);
$transactionSave = $this->_transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
$transactionSave->save();
}
return $shipment;
}
} catch (Exception $e) {
throw new MagentoFrameworkExceptionLocalizedException(
__($e->getMessage())
);
}
}

/**
* @param $order MagentoSalesModelOrder
* @param $track array
* @return $this
*/
protected function prepareShipment($order, $track)
{
$shipment = $this->_shipmentFactory->create(
$order,
$this->prepareShipmentItems($order),
$track
);
return $shipment->getTotalQty() ? $shipment->register() : false;
}

/**
* @param $order MagentoSalesModelOrder
* @return array
*/
protected function prepareShipmentItems($order)
{
$items = [];

foreach($order->getAllItems() as $item) {
$items[$item->getItemId()] = $item->getQtyOrdered();
}
return $items;
}
//after prepareShipmentItems function

/*excecute function*/
public execute()
{
// enter the number of data fields you require the product row inside the CSV file to contain

$required_data_fields = 3; //number of column in csv
//$header = fgetcsv($file); // get data headers and skip 1st row

while (($row = fgetcsv($file, 100, ",")) !== FALSE)
//while ( $row = fgetcsv($file, 100, ",") )
//while (($row = fgetcsv($file)) !== FALSE)
{
$data_count = count($row);
if ($data_count < 1) {
continue;
}

$data = array();
//$data = array_combine($header, $row);
$data = array($row);

$ponumber = $data[0]; //$data['ponumber']; // column A
if ($data_count < $required_data_fields) {
$logger->info("Skipping Order Number " . $ponumber . ". Not enough data to import.");
continue;
}
$shipvia = trim($data[1]); //trim($data['shipvia']); // column B
$trackingnumber = trim($data[2]);//trim($data['trackingnumber']); // column C

echo 'Updating Order: '.$ponumber.', with Tracking: '.$shipvia.':'.$trackingnumber.'<br />n';

///////////////////////////////start adding tracking///////////////////////////////

print_r($row);
//createShipment($ponumber, $trackingnumber); /* @param int $orderId@param | @param string $trackingNumber */

///////////////////////////////end of adding tracking///////////////////////////////

}// end of while loop


fclose($file);
}//end of execute function

} // end of class shipmentobject


/**
* @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
* @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
* @param MagentoFrameworkDBTransactionFactory $transactionFactory
* @param MagentoSalesApiOrderRepositoryInterface $orderRepository
*/
//create new class object
$test = new ShipmentObject('','','',''); // what value to assign here?
$test->execute();
}









share|improve this question





























    1















    i am trying to get tracking from csv and load to magento 2 order programmatically.
    i grabbed the create shipment & add tracking code from here https://www.scommerce-mage.com/blog/magento-2-how-to-create-shipment-programatically.html, and add an execute function (line 122) to load data from csv. but i'm not sure how to create an shipment object (line 175).



    <?php
    $file = fopen('track.csv', 'r', '"'); // set path to the CSV file
    if ($file !== false)
    {
    require __DIR__ . '/app/bootstrap.php';
    $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $state = $objectManager->get('MagentoFrameworkAppState');
    $state->setAreaCode('adminhtml');
    // add logging capability
    $writer = new ZendLogWriterStream(BP . '/var/log/import-update.log');
    $logger = new ZendLogLogger();
    $logger->addWriter($writer);

    class ShipmentObject{
    /*There are two main functions
    prepareShipment of MagentoSalesModelOrderShipmentFactory class which prepare invoice and
    addObject of MagentoFrameworkDBTransactionFactory class which helps to create shipment and associate the shipment with original order in Magento 2.
    */

    /**
    * @var MagentoSalesModelOrderShipmentTrackFactory
    */
    protected $_shipmentTrackFactory;

    /**
    * @var MagentoSalesModelOrderShipmentFactory
    */
    protected $_shipmentFactory;

    /**
    * @var MagentoFrameworkDBTransactionFactory
    */
    protected $_transactionFactory;

    /**
    * @var MagentoSalesApiOrderRepositoryInterface
    */
    protected $_orderRepository;

    /**
    * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
    * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
    * @param MagentoFrameworkDBTransactionFactory $transactionFactory
    * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
    */
    public function __construct(
    MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory,
    MagentoSalesModelOrderShipmentFactory $shipmentFactory,
    MagentoFrameworkDBTransactionFactory $transactionFactory,
    MagentoSalesApiOrderRepositoryInterface $orderRepository
    ) {
    $this->_shipmentTrackFactory = $shipmentTrackFactory;
    $this->_shipmentFactory = $shipmentFactory;
    $this->_transactionFactory = $transactionFactory;
    $this->_orderRepository = $orderRepository;
    }

    /**
    * @param int $orderId
    * @param string $trackingNumber
    * @return MagentoSalesModelShipment $shipment
    */
    protected function createShipment($orderId, $trackingNumber)
    {
    try {
    $order = $this->_orderRepository->get($orderId);
    if ($order){
    $data = array(array(
    'carrier_code' => $order->getShippingMethod(), //'carrier_code' => 'fedex', // need to lower case
    'title' => $order->getShippingDescription(), //'title' => 'Federal Express', // how to set here 'Federal Express' or 'United Parcel Service'
    'number' => $trackingNumber, //$trackingnumber,
    ));

    $shipment = $this->prepareShipment($order, $data);
    if ($shipment) {
    $order->setIsInProcess(true);
    $order->addStatusHistoryComment('Automatically SHIPPED', false);
    $transactionSave = $this->_transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
    $transactionSave->save();
    }
    return $shipment;
    }
    } catch (Exception $e) {
    throw new MagentoFrameworkExceptionLocalizedException(
    __($e->getMessage())
    );
    }
    }

    /**
    * @param $order MagentoSalesModelOrder
    * @param $track array
    * @return $this
    */
    protected function prepareShipment($order, $track)
    {
    $shipment = $this->_shipmentFactory->create(
    $order,
    $this->prepareShipmentItems($order),
    $track
    );
    return $shipment->getTotalQty() ? $shipment->register() : false;
    }

    /**
    * @param $order MagentoSalesModelOrder
    * @return array
    */
    protected function prepareShipmentItems($order)
    {
    $items = [];

    foreach($order->getAllItems() as $item) {
    $items[$item->getItemId()] = $item->getQtyOrdered();
    }
    return $items;
    }
    //after prepareShipmentItems function

    /*excecute function*/
    public execute()
    {
    // enter the number of data fields you require the product row inside the CSV file to contain

    $required_data_fields = 3; //number of column in csv
    //$header = fgetcsv($file); // get data headers and skip 1st row

    while (($row = fgetcsv($file, 100, ",")) !== FALSE)
    //while ( $row = fgetcsv($file, 100, ",") )
    //while (($row = fgetcsv($file)) !== FALSE)
    {
    $data_count = count($row);
    if ($data_count < 1) {
    continue;
    }

    $data = array();
    //$data = array_combine($header, $row);
    $data = array($row);

    $ponumber = $data[0]; //$data['ponumber']; // column A
    if ($data_count < $required_data_fields) {
    $logger->info("Skipping Order Number " . $ponumber . ". Not enough data to import.");
    continue;
    }
    $shipvia = trim($data[1]); //trim($data['shipvia']); // column B
    $trackingnumber = trim($data[2]);//trim($data['trackingnumber']); // column C

    echo 'Updating Order: '.$ponumber.', with Tracking: '.$shipvia.':'.$trackingnumber.'<br />n';

    ///////////////////////////////start adding tracking///////////////////////////////

    print_r($row);
    //createShipment($ponumber, $trackingnumber); /* @param int $orderId@param | @param string $trackingNumber */

    ///////////////////////////////end of adding tracking///////////////////////////////

    }// end of while loop


    fclose($file);
    }//end of execute function

    } // end of class shipmentobject


    /**
    * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
    * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
    * @param MagentoFrameworkDBTransactionFactory $transactionFactory
    * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
    */
    //create new class object
    $test = new ShipmentObject('','','',''); // what value to assign here?
    $test->execute();
    }









    share|improve this question

























      1












      1








      1








      i am trying to get tracking from csv and load to magento 2 order programmatically.
      i grabbed the create shipment & add tracking code from here https://www.scommerce-mage.com/blog/magento-2-how-to-create-shipment-programatically.html, and add an execute function (line 122) to load data from csv. but i'm not sure how to create an shipment object (line 175).



      <?php
      $file = fopen('track.csv', 'r', '"'); // set path to the CSV file
      if ($file !== false)
      {
      require __DIR__ . '/app/bootstrap.php';
      $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
      $objectManager = $bootstrap->getObjectManager();
      $state = $objectManager->get('MagentoFrameworkAppState');
      $state->setAreaCode('adminhtml');
      // add logging capability
      $writer = new ZendLogWriterStream(BP . '/var/log/import-update.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);

      class ShipmentObject{
      /*There are two main functions
      prepareShipment of MagentoSalesModelOrderShipmentFactory class which prepare invoice and
      addObject of MagentoFrameworkDBTransactionFactory class which helps to create shipment and associate the shipment with original order in Magento 2.
      */

      /**
      * @var MagentoSalesModelOrderShipmentTrackFactory
      */
      protected $_shipmentTrackFactory;

      /**
      * @var MagentoSalesModelOrderShipmentFactory
      */
      protected $_shipmentFactory;

      /**
      * @var MagentoFrameworkDBTransactionFactory
      */
      protected $_transactionFactory;

      /**
      * @var MagentoSalesApiOrderRepositoryInterface
      */
      protected $_orderRepository;

      /**
      * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
      * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
      * @param MagentoFrameworkDBTransactionFactory $transactionFactory
      * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
      */
      public function __construct(
      MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory,
      MagentoSalesModelOrderShipmentFactory $shipmentFactory,
      MagentoFrameworkDBTransactionFactory $transactionFactory,
      MagentoSalesApiOrderRepositoryInterface $orderRepository
      ) {
      $this->_shipmentTrackFactory = $shipmentTrackFactory;
      $this->_shipmentFactory = $shipmentFactory;
      $this->_transactionFactory = $transactionFactory;
      $this->_orderRepository = $orderRepository;
      }

      /**
      * @param int $orderId
      * @param string $trackingNumber
      * @return MagentoSalesModelShipment $shipment
      */
      protected function createShipment($orderId, $trackingNumber)
      {
      try {
      $order = $this->_orderRepository->get($orderId);
      if ($order){
      $data = array(array(
      'carrier_code' => $order->getShippingMethod(), //'carrier_code' => 'fedex', // need to lower case
      'title' => $order->getShippingDescription(), //'title' => 'Federal Express', // how to set here 'Federal Express' or 'United Parcel Service'
      'number' => $trackingNumber, //$trackingnumber,
      ));

      $shipment = $this->prepareShipment($order, $data);
      if ($shipment) {
      $order->setIsInProcess(true);
      $order->addStatusHistoryComment('Automatically SHIPPED', false);
      $transactionSave = $this->_transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
      $transactionSave->save();
      }
      return $shipment;
      }
      } catch (Exception $e) {
      throw new MagentoFrameworkExceptionLocalizedException(
      __($e->getMessage())
      );
      }
      }

      /**
      * @param $order MagentoSalesModelOrder
      * @param $track array
      * @return $this
      */
      protected function prepareShipment($order, $track)
      {
      $shipment = $this->_shipmentFactory->create(
      $order,
      $this->prepareShipmentItems($order),
      $track
      );
      return $shipment->getTotalQty() ? $shipment->register() : false;
      }

      /**
      * @param $order MagentoSalesModelOrder
      * @return array
      */
      protected function prepareShipmentItems($order)
      {
      $items = [];

      foreach($order->getAllItems() as $item) {
      $items[$item->getItemId()] = $item->getQtyOrdered();
      }
      return $items;
      }
      //after prepareShipmentItems function

      /*excecute function*/
      public execute()
      {
      // enter the number of data fields you require the product row inside the CSV file to contain

      $required_data_fields = 3; //number of column in csv
      //$header = fgetcsv($file); // get data headers and skip 1st row

      while (($row = fgetcsv($file, 100, ",")) !== FALSE)
      //while ( $row = fgetcsv($file, 100, ",") )
      //while (($row = fgetcsv($file)) !== FALSE)
      {
      $data_count = count($row);
      if ($data_count < 1) {
      continue;
      }

      $data = array();
      //$data = array_combine($header, $row);
      $data = array($row);

      $ponumber = $data[0]; //$data['ponumber']; // column A
      if ($data_count < $required_data_fields) {
      $logger->info("Skipping Order Number " . $ponumber . ". Not enough data to import.");
      continue;
      }
      $shipvia = trim($data[1]); //trim($data['shipvia']); // column B
      $trackingnumber = trim($data[2]);//trim($data['trackingnumber']); // column C

      echo 'Updating Order: '.$ponumber.', with Tracking: '.$shipvia.':'.$trackingnumber.'<br />n';

      ///////////////////////////////start adding tracking///////////////////////////////

      print_r($row);
      //createShipment($ponumber, $trackingnumber); /* @param int $orderId@param | @param string $trackingNumber */

      ///////////////////////////////end of adding tracking///////////////////////////////

      }// end of while loop


      fclose($file);
      }//end of execute function

      } // end of class shipmentobject


      /**
      * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
      * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
      * @param MagentoFrameworkDBTransactionFactory $transactionFactory
      * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
      */
      //create new class object
      $test = new ShipmentObject('','','',''); // what value to assign here?
      $test->execute();
      }









      share|improve this question














      i am trying to get tracking from csv and load to magento 2 order programmatically.
      i grabbed the create shipment & add tracking code from here https://www.scommerce-mage.com/blog/magento-2-how-to-create-shipment-programatically.html, and add an execute function (line 122) to load data from csv. but i'm not sure how to create an shipment object (line 175).



      <?php
      $file = fopen('track.csv', 'r', '"'); // set path to the CSV file
      if ($file !== false)
      {
      require __DIR__ . '/app/bootstrap.php';
      $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
      $objectManager = $bootstrap->getObjectManager();
      $state = $objectManager->get('MagentoFrameworkAppState');
      $state->setAreaCode('adminhtml');
      // add logging capability
      $writer = new ZendLogWriterStream(BP . '/var/log/import-update.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);

      class ShipmentObject{
      /*There are two main functions
      prepareShipment of MagentoSalesModelOrderShipmentFactory class which prepare invoice and
      addObject of MagentoFrameworkDBTransactionFactory class which helps to create shipment and associate the shipment with original order in Magento 2.
      */

      /**
      * @var MagentoSalesModelOrderShipmentTrackFactory
      */
      protected $_shipmentTrackFactory;

      /**
      * @var MagentoSalesModelOrderShipmentFactory
      */
      protected $_shipmentFactory;

      /**
      * @var MagentoFrameworkDBTransactionFactory
      */
      protected $_transactionFactory;

      /**
      * @var MagentoSalesApiOrderRepositoryInterface
      */
      protected $_orderRepository;

      /**
      * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
      * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
      * @param MagentoFrameworkDBTransactionFactory $transactionFactory
      * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
      */
      public function __construct(
      MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory,
      MagentoSalesModelOrderShipmentFactory $shipmentFactory,
      MagentoFrameworkDBTransactionFactory $transactionFactory,
      MagentoSalesApiOrderRepositoryInterface $orderRepository
      ) {
      $this->_shipmentTrackFactory = $shipmentTrackFactory;
      $this->_shipmentFactory = $shipmentFactory;
      $this->_transactionFactory = $transactionFactory;
      $this->_orderRepository = $orderRepository;
      }

      /**
      * @param int $orderId
      * @param string $trackingNumber
      * @return MagentoSalesModelShipment $shipment
      */
      protected function createShipment($orderId, $trackingNumber)
      {
      try {
      $order = $this->_orderRepository->get($orderId);
      if ($order){
      $data = array(array(
      'carrier_code' => $order->getShippingMethod(), //'carrier_code' => 'fedex', // need to lower case
      'title' => $order->getShippingDescription(), //'title' => 'Federal Express', // how to set here 'Federal Express' or 'United Parcel Service'
      'number' => $trackingNumber, //$trackingnumber,
      ));

      $shipment = $this->prepareShipment($order, $data);
      if ($shipment) {
      $order->setIsInProcess(true);
      $order->addStatusHistoryComment('Automatically SHIPPED', false);
      $transactionSave = $this->_transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
      $transactionSave->save();
      }
      return $shipment;
      }
      } catch (Exception $e) {
      throw new MagentoFrameworkExceptionLocalizedException(
      __($e->getMessage())
      );
      }
      }

      /**
      * @param $order MagentoSalesModelOrder
      * @param $track array
      * @return $this
      */
      protected function prepareShipment($order, $track)
      {
      $shipment = $this->_shipmentFactory->create(
      $order,
      $this->prepareShipmentItems($order),
      $track
      );
      return $shipment->getTotalQty() ? $shipment->register() : false;
      }

      /**
      * @param $order MagentoSalesModelOrder
      * @return array
      */
      protected function prepareShipmentItems($order)
      {
      $items = [];

      foreach($order->getAllItems() as $item) {
      $items[$item->getItemId()] = $item->getQtyOrdered();
      }
      return $items;
      }
      //after prepareShipmentItems function

      /*excecute function*/
      public execute()
      {
      // enter the number of data fields you require the product row inside the CSV file to contain

      $required_data_fields = 3; //number of column in csv
      //$header = fgetcsv($file); // get data headers and skip 1st row

      while (($row = fgetcsv($file, 100, ",")) !== FALSE)
      //while ( $row = fgetcsv($file, 100, ",") )
      //while (($row = fgetcsv($file)) !== FALSE)
      {
      $data_count = count($row);
      if ($data_count < 1) {
      continue;
      }

      $data = array();
      //$data = array_combine($header, $row);
      $data = array($row);

      $ponumber = $data[0]; //$data['ponumber']; // column A
      if ($data_count < $required_data_fields) {
      $logger->info("Skipping Order Number " . $ponumber . ". Not enough data to import.");
      continue;
      }
      $shipvia = trim($data[1]); //trim($data['shipvia']); // column B
      $trackingnumber = trim($data[2]);//trim($data['trackingnumber']); // column C

      echo 'Updating Order: '.$ponumber.', with Tracking: '.$shipvia.':'.$trackingnumber.'<br />n';

      ///////////////////////////////start adding tracking///////////////////////////////

      print_r($row);
      //createShipment($ponumber, $trackingnumber); /* @param int $orderId@param | @param string $trackingNumber */

      ///////////////////////////////end of adding tracking///////////////////////////////

      }// end of while loop


      fclose($file);
      }//end of execute function

      } // end of class shipmentobject


      /**
      * @param MagentoSalesModelOrderShipmentTrackFactory $shipmentTrackFactory
      * @param MagentoSalesModelOrderShipmentFactory $shipmentFactory
      * @param MagentoFrameworkDBTransactionFactory $transactionFactory
      * @param MagentoSalesApiOrderRepositoryInterface $orderRepository
      */
      //create new class object
      $test = new ShipmentObject('','','',''); // what value to assign here?
      $test->execute();
      }






      magento2 php shipment object-manager shipment-tracking






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 12 mins ago









      Kris WenKris Wen

      1368




      1368






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268995%2fhow-do-i-create-a-shipment-class-object-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268995%2fhow-do-i-create-a-shipment-class-object-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...