IndexDataByStockIdProvider.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\InventoryConfigurableProductIndexer\Indexer\Stock;
  8. use ArrayIterator;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\InventoryConfigurableProductIndexer\Indexer\SelectBuilder;
  11. /**
  12. * Returns all data for the index by stock id condition
  13. */
  14. class IndexDataByStockIdProvider
  15. {
  16. /**
  17. * @var ResourceConnection
  18. */
  19. private $resourceConnection;
  20. /**
  21. * @var SelectBuilder
  22. */
  23. private $selectBuilder;
  24. /**
  25. * @param ResourceConnection $resourceConnection
  26. * @param SelectBuilder $selectBuilder
  27. */
  28. public function __construct(
  29. ResourceConnection $resourceConnection,
  30. SelectBuilder $selectBuilder
  31. ) {
  32. $this->resourceConnection = $resourceConnection;
  33. $this->selectBuilder = $selectBuilder;
  34. }
  35. /**
  36. * @param int $stockId
  37. * @return ArrayIterator
  38. */
  39. public function execute(int $stockId): ArrayIterator
  40. {
  41. $select = $this->selectBuilder->execute($stockId);
  42. $connection = $this->resourceConnection->getConnection();
  43. return new ArrayIterator($connection->fetchAll($select));
  44. }
  45. }