IsSourceItemManagementAllowedForSku.php 1.7 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\InventoryConfiguration\Model;
  8. use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;
  9. use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface;
  10. use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForSkuInterface;
  11. class IsSourceItemManagementAllowedForSku implements IsSourceItemManagementAllowedForSkuInterface
  12. {
  13. /**
  14. * @var GetProductTypesBySkusInterface
  15. */
  16. private $getProductTypesBySkus;
  17. /**
  18. * @var IsSourceItemManagementAllowedForProductTypeInterface
  19. */
  20. private $isSourceItemManagementAllowedForProductType;
  21. /**
  22. * @param GetProductTypesBySkusInterface $getProductTypesBySkus
  23. * @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
  24. */
  25. public function __construct(
  26. GetProductTypesBySkusInterface $getProductTypesBySkus,
  27. IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
  28. ) {
  29. $this->getProductTypesBySkus = $getProductTypesBySkus;
  30. $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function execute(string $sku): bool
  36. {
  37. $productType = $this->getProductTypesBySkus->execute([$sku]);
  38. if (isset($productType[$sku])) {
  39. $typeId = $productType[$sku];
  40. } else {
  41. return false;
  42. }
  43. return $this->isSourceItemManagementAllowedForProductType->execute($typeId);
  44. }
  45. }