StockResolver.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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;
  8. use Magento\InventoryApi\Api\Data\StockInterface;
  9. use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
  10. use Magento\InventorySalesApi\Api\Data\SalesChannelInterfaceFactory;
  11. use Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface;
  12. use Magento\InventorySalesApi\Api\StockResolverInterface;
  13. /**
  14. * @inheritdoc
  15. */
  16. class StockResolver implements StockResolverInterface
  17. {
  18. /**
  19. * @var GetStockBySalesChannelInterface
  20. */
  21. private $getStockBySalesChannel;
  22. /**
  23. * @var SalesChannelInterfaceFactory
  24. */
  25. private $salesChannelInterfaceFactory;
  26. /**
  27. * @param GetStockBySalesChannelInterface $getStockBySalesChannel
  28. * @param SalesChannelInterfaceFactory $salesChannelInterfaceFactory
  29. */
  30. public function __construct(
  31. GetStockBySalesChannelInterface $getStockBySalesChannel,
  32. SalesChannelInterfaceFactory $salesChannelInterfaceFactory
  33. ) {
  34. $this->getStockBySalesChannel = $getStockBySalesChannel;
  35. $this->salesChannelInterfaceFactory = $salesChannelInterfaceFactory;
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function execute(string $type, string $code): StockInterface
  41. {
  42. $salesChannel = $this->salesChannelInterfaceFactory->create([
  43. 'data' => [
  44. SalesChannelInterface::TYPE => $type,
  45. SalesChannelInterface::CODE => $code
  46. ]
  47. ]);
  48. return $this->getStockBySalesChannel->execute($salesChannel);
  49. }
  50. }