GetAssignedSalesChannelsDataForStock.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\InventorySales\Model\ResourceModel;
  8. use Magento\Framework\App\ResourceConnection;
  9. /**
  10. * Provides linked sales channels by given stock id
  11. */
  12. class GetAssignedSalesChannelsDataForStock
  13. {
  14. /**
  15. * @var ResourceConnection
  16. */
  17. private $resourceConnection;
  18. /**
  19. * @param ResourceConnection $resourceConnection
  20. */
  21. public function __construct(
  22. ResourceConnection $resourceConnection
  23. ) {
  24. $this->resourceConnection = $resourceConnection;
  25. }
  26. /**
  27. * Given a stock id, return array of sales channels assigned to it
  28. *
  29. * @param int $stockId
  30. * @return array
  31. */
  32. public function execute(int $stockId): array
  33. {
  34. $connection = $this->resourceConnection->getConnection();
  35. $tableName = $this->resourceConnection->getTableName('inventory_stock_sales_channel');
  36. $select = $connection->select()
  37. ->from($tableName)
  38. ->where('stock_id = ?', $stockId);
  39. return $connection->fetchAll($select);
  40. }
  41. }