Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockIdResolver.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
18 {
22  private $resourceConnection;
23 
27  public function __construct(
28  ResourceConnection $resourceConnection
29  ) {
30  $this->resourceConnection = $resourceConnection;
31  }
32 
40  public function resolve(string $type, string $code)
41  {
42  $connection = $this->resourceConnection->getConnection();
43  $tableName = $this->resourceConnection->getTableName('inventory_stock_sales_channel');
44 
45  $select = $connection->select()
46  ->from($tableName, 'stock_id')
47  ->where(SalesChannelInterface::TYPE . ' = ?', $type)
48  ->where(SalesChannelInterface::CODE . ' = ?', $code);
49 
50  $stockId = $connection->fetchOne($select);
51  return false === $stockId ? null : (int)$stockId;
52  }
53 }
$tableName
Definition: trigger.php:13
$type
Definition: item.phtml:13
__construct(ResourceConnection $resourceConnection)
$connection
Definition: bulk.php:13
$code
Definition: info.phtml:12