Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetProductIdsBySourceItemIds.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $resource;
23 
27  private $productTableName;
28 
33  public function __construct(
34  ResourceConnection $resource,
35  string $productTableName
36  ) {
37  $this->resource = $resource;
38  $this->productTableName = $productTableName;
39  }
40 
47  public function execute(array $sourceItemIds): array
48  {
49  $connection = $this->resource->getConnection();
50  $select = $connection->select()
51  ->from(
52  ['source_item' => $this->resource->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)],
53  []
54  )->where(
55  'source_item.' . SourceItem::ID_FIELD_NAME . ' IN (?)',
56  $sourceItemIds
57  )->join(
58  ['product' => $this->resource->getTableName($this->productTableName)],
59  'source_item.' . SourceItemInterface::SKU . ' = product.sku',
60  ['product.entity_id']
61  )->distinct();
62 
63  return $connection->fetchCol($select);
64  }
65 }
$resource
Definition: bulk.php:12
$connection
Definition: bulk.php:13