StockRepository.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Inventory\Model;
  8. use Magento\Framework\Api\SearchCriteriaInterface;
  9. use Magento\Inventory\Model\Stock\Command\DeleteByIdInterface;
  10. use Magento\Inventory\Model\Stock\Command\GetInterface;
  11. use Magento\Inventory\Model\Stock\Command\GetListInterface;
  12. use Magento\Inventory\Model\Stock\Command\SaveInterface;
  13. use Magento\InventoryApi\Api\Data\StockInterface;
  14. use Magento\InventoryApi\Api\Data\StockSearchResultsInterface;
  15. use Magento\InventoryApi\Api\StockRepositoryInterface;
  16. /**
  17. * @inheritdoc
  18. */
  19. class StockRepository implements StockRepositoryInterface
  20. {
  21. /**
  22. * @var SaveInterface
  23. */
  24. private $commandSave;
  25. /**
  26. * @var GetInterface
  27. */
  28. private $commandGet;
  29. /**
  30. * @var DeleteByIdInterface
  31. */
  32. private $commandDeleteById;
  33. /**
  34. * @var GetListInterface
  35. */
  36. private $commandGetList;
  37. /**
  38. * @param SaveInterface $commandSave
  39. * @param GetInterface $commandGet
  40. * @param DeleteByIdInterface $commandDeleteById
  41. * @param GetListInterface $commandGetList
  42. */
  43. public function __construct(
  44. SaveInterface $commandSave,
  45. GetInterface $commandGet,
  46. DeleteByIdInterface $commandDeleteById,
  47. GetListInterface $commandGetList
  48. ) {
  49. $this->commandSave = $commandSave;
  50. $this->commandGet = $commandGet;
  51. $this->commandDeleteById = $commandDeleteById;
  52. $this->commandGetList = $commandGetList;
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function save(StockInterface $stock): int
  58. {
  59. return $this->commandSave->execute($stock);
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function get(int $stockId): StockInterface
  65. {
  66. return $this->commandGet->execute($stockId);
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function deleteById(int $stockId): void
  72. {
  73. $this->commandDeleteById->execute($stockId);
  74. }
  75. /**
  76. * @inheritdoc
  77. */
  78. public function getList(SearchCriteriaInterface $searchCriteria = null): StockSearchResultsInterface
  79. {
  80. return $this->commandGetList->execute($searchCriteria);
  81. }
  82. }