Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IsProductAssignedToStock.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
16 {
20  private $resource;
21 
25  public function __construct(
26  ResourceConnection $resource
27  ) {
28  $this->resource = $resource;
29  }
30 
34  public function execute(string $sku, int $stockId): bool
35  {
36  $connection = $this->resource->getConnection();
37  $select = $connection->select()
38  ->from(
39  ['stock_source_link' => $this->resource->getTableName(StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK)]
40  )->join(
41  ['inventory_source_item' => $this->resource->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)],
42  'inventory_source_item.' . SourceItemInterface::SOURCE_CODE . '
43  = stock_source_link.' . SourceItemInterface::SOURCE_CODE,
44  []
45  )->where(
46  'stock_source_link.' . StockSourceLinkInterface::STOCK_ID . ' = ?',
47  $stockId
48  )->where(
49  'inventory_source_item.' . SourceItemInterface::SKU . ' = ?',
50  $sku
51  );
52 
53  return (bool)$connection->fetchOne($select);
54  }
55 }
$resource
Definition: bulk.php:12
$connection
Definition: bulk.php:13