Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetSourceCodeByShipmentId.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
16 {
20  const SHIPMENT_ID = 'shipment_id';
21  const SOURCE_CODE = 'source_code';
22 
26  private $resourceConnection;
27 
31  public function __construct(ResourceConnection $resourceConnection)
32  {
33  $this->resourceConnection = $resourceConnection;
34  }
35 
42  public function execute(int $shipmentId)
43  {
44  $connection = $this->resourceConnection->getConnection();
45  $tableName = $this->resourceConnection
46  ->getTableName('inventory_shipment_source');
47 
48  $select = $connection->select()
49  ->from($tableName, [
50  self::SOURCE_CODE => self::SOURCE_CODE
51  ])
52  ->where(self::SHIPMENT_ID . ' = ?', $shipmentId)
53  ->limit(1);
54 
55  $sourceCode = $connection->fetchOne($select);
56 
57  return $sourceCode ?: null;
58  }
59 }
$tableName
Definition: trigger.php:13
$sourceCode
Definition: inventory.phtml:11
$connection
Definition: bulk.php:13