RmaShipmentManagement.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Rma;
  6. use Magento\Framework\Exception\CouldNotSaveException;
  7. use Temando\Shipping\Api\Rma\RmaShipmentManagementInterface;
  8. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  9. use Temando\Shipping\Model\ResourceModel\Repository\RmaShipmentRepositoryInterface;
  10. /**
  11. * Manage RMA Shipments
  12. *
  13. * @package Temando\Shipping\Api
  14. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. */
  18. class RmaShipmentManagement implements RmaShipmentManagementInterface
  19. {
  20. /**
  21. * @var RmaShipmentRepositoryInterface
  22. */
  23. private $rmaShipmentRepository;
  24. /**
  25. * @var ModuleConfigInterface
  26. */
  27. private $moduleConfig;
  28. /**
  29. * RmaShipmentManagement constructor.
  30. *
  31. * @param RmaShipmentRepositoryInterface $rmaShipmentRepository
  32. * @param ModuleConfigInterface $moduleConfig
  33. */
  34. public function __construct(
  35. RmaShipmentRepositoryInterface $rmaShipmentRepository,
  36. ModuleConfigInterface $moduleConfig
  37. ) {
  38. $this->rmaShipmentRepository = $rmaShipmentRepository;
  39. $this->moduleConfig = $moduleConfig;
  40. }
  41. /**
  42. * Assign platform shipment IDs to a core RMA entity.
  43. *
  44. * @param int $rmaId
  45. * @param string[] $returnShipmentIds
  46. *
  47. * @return int Number of successfully assigned shipment IDs.
  48. * @throws \Magento\Framework\Exception\LocalizedException
  49. */
  50. public function assignShipmentIds($rmaId, array $returnShipmentIds)
  51. {
  52. if (!$this->moduleConfig->isRmaAvailable()) {
  53. throw new CouldNotSaveException(__('RMA is not available'));
  54. }
  55. return $this->rmaShipmentRepository->saveShipmentIds($rmaId, $returnShipmentIds);
  56. }
  57. }