GetDefaultValues.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\InventoryLowQuantityNotification\Model\SourceItemConfiguration;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;
  10. /**
  11. * Get default configuration values from system config
  12. */
  13. class GetDefaultValues
  14. {
  15. /**
  16. * Default Notify Stock Qty config path
  17. */
  18. const XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty';
  19. /**
  20. * @var ScopeConfigInterface
  21. */
  22. private $scopeConfig;
  23. /**
  24. * @param ScopeConfigInterface $scopeConfig
  25. */
  26. public function __construct(
  27. ScopeConfigInterface $scopeConfig
  28. ) {
  29. $this->scopeConfig = $scopeConfig;
  30. }
  31. /**
  32. * @param string $sourceCode
  33. * @param string $sku
  34. * @return array
  35. */
  36. public function execute(string $sourceCode, string $sku) : array
  37. {
  38. $inventoryNotifyQty = (float)$this->scopeConfig->getValue(self::XML_PATH_NOTIFY_STOCK_QTY);
  39. $defaultConfiguration = [
  40. SourceItemConfigurationInterface::SOURCE_CODE => $sourceCode,
  41. SourceItemConfigurationInterface::SKU => $sku,
  42. SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY => $inventoryNotifyQty,
  43. ];
  44. return $defaultConfiguration;
  45. }
  46. }