Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetAssignedStockIdForWebsite.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $resourceConnection;
23 
27  public function __construct(
28  ResourceConnection $resourceConnection
29  ) {
30  $this->resourceConnection = $resourceConnection;
31  }
32 
36  public function execute(string $websiteCode): ?int
37  {
38  $connection = $this->resourceConnection->getConnection();
39  $tableName = $this->resourceConnection->getTableName('inventory_stock_sales_channel');
40 
41  $select = $connection->select()
42  ->from($tableName, ['stock_id'])
43  ->where('code = ?', $websiteCode)
44  ->where('type = ?', SalesChannelInterface::TYPE_WEBSITE);
45 
46  $result = $connection->fetchCol($select);
47 
48  if (count($result) === 0) {
49  return null;
50  }
51  return (int)reset($result);
52  }
53 }
$tableName
Definition: trigger.php:13
$connection
Definition: bulk.php:13
if(!isset($_GET['website_code'])) $websiteCode
Definition: website.php:11