GetAllStockIds.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryIndexer\Indexer\Stock;
  8. use Magento\Framework\App\ResourceConnection;
  9. use Magento\Inventory\Model\ResourceModel\Stock as StockResourceModel;
  10. use Magento\Inventory\Model\StockSourceLink;
  11. /**
  12. * Returns all stock ids.
  13. */
  14. class GetAllStockIds
  15. {
  16. /**
  17. * @var ResourceConnection
  18. */
  19. private $resourceConnection;
  20. /**
  21. * @param ResourceConnection $resourceConnection
  22. */
  23. public function __construct(ResourceConnection $resourceConnection)
  24. {
  25. $this->resourceConnection = $resourceConnection;
  26. }
  27. /**
  28. * @return int[]
  29. */
  30. public function execute(): array
  31. {
  32. $connection = $this->resourceConnection->getConnection();
  33. $stockTable = $this->resourceConnection->getTableName(StockResourceModel::TABLE_NAME_STOCK);
  34. $select = $connection->select()->from($stockTable, StockSourceLink::STOCK_ID);
  35. $stockIds = $connection->fetchCol($select);
  36. $stockIds = array_map('intval', $stockIds);
  37. return $stockIds;
  38. }
  39. }