SaveMultiple.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Exception\CouldNotSaveException;
  9. use Magento\Framework\Exception\InputException;
  10. use Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration\SaveMultiple
  11. as SaveMultipleResourceModel;
  12. use Magento\InventoryLowQuantityNotificationApi\Api\SourceItemConfigurationsSaveInterface;
  13. use Psr\Log\LoggerInterface;
  14. /**
  15. * @inheritdoc
  16. */
  17. class SaveMultiple implements SourceItemConfigurationsSaveInterface
  18. {
  19. /**
  20. * @var SaveMultipleResourceModel
  21. */
  22. private $saveMultipleResourceModel;
  23. /**
  24. * @var LoggerInterface
  25. */
  26. private $logger;
  27. /**
  28. * @param SaveMultipleResourceModel $saveMultipleResourceModel
  29. * @param LoggerInterface $logger
  30. */
  31. public function __construct(
  32. SaveMultipleResourceModel $saveMultipleResourceModel,
  33. LoggerInterface $logger
  34. ) {
  35. $this->saveMultipleResourceModel = $saveMultipleResourceModel;
  36. $this->logger = $logger;
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function execute(array $sourceItemConfigurations): void
  42. {
  43. if (empty($sourceItemConfigurations)) {
  44. throw new InputException(__('Input data is empty'));
  45. }
  46. try {
  47. $this->saveMultipleResourceModel->execute($sourceItemConfigurations);
  48. } catch (\Exception $e) {
  49. $this->logger->error($e->getMessage());
  50. throw new CouldNotSaveException(__('Could not save Source Item Configuration'), $e);
  51. }
  52. }
  53. }