InvoiceOrder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Validation;
  7. use Magento\Sales\Api\Data\InvoiceCommentCreationInterface;
  8. use Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface;
  9. use Magento\Sales\Api\Data\InvoiceInterface;
  10. use Magento\Sales\Api\Data\OrderInterface;
  11. use Magento\Sales\Model\Order\Invoice\InvoiceValidatorInterface;
  12. use Magento\Sales\Model\Order\InvoiceQuantityValidator;
  13. use Magento\Sales\Model\Order\OrderValidatorInterface;
  14. use Magento\Sales\Model\ValidatorResultInterface;
  15. use Magento\Sales\Model\ValidatorResultMerger;
  16. /**
  17. * Class InvoiceOrder
  18. * Validation for invoice order operation
  19. */
  20. class InvoiceOrder implements InvoiceOrderInterface
  21. {
  22. /**
  23. * @var InvoiceValidatorInterface
  24. */
  25. private $invoiceValidator;
  26. /**
  27. * @var OrderValidatorInterface
  28. */
  29. private $orderValidator;
  30. /**
  31. * @var ValidatorResultMerger
  32. */
  33. private $validatorResultMerger;
  34. /**
  35. * InvoiceOrder constructor.
  36. * @param InvoiceValidatorInterface $invoiceValidator
  37. * @param OrderValidatorInterface $orderValidator
  38. * @param ValidatorResultMerger $validatorResultMerger
  39. */
  40. public function __construct(
  41. InvoiceValidatorInterface $invoiceValidator,
  42. OrderValidatorInterface $orderValidator,
  43. ValidatorResultMerger $validatorResultMerger
  44. ) {
  45. $this->invoiceValidator = $invoiceValidator;
  46. $this->orderValidator = $orderValidator;
  47. $this->validatorResultMerger = $validatorResultMerger;
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function validate(
  53. OrderInterface $order,
  54. InvoiceInterface $invoice,
  55. $capture = false,
  56. array $items = [],
  57. $notify = false,
  58. $appendComment = false,
  59. InvoiceCommentCreationInterface $comment = null,
  60. InvoiceCreationArgumentsInterface $arguments = null
  61. ) {
  62. return $this->validatorResultMerger->merge(
  63. $this->invoiceValidator->validate(
  64. $invoice,
  65. [InvoiceQuantityValidator::class]
  66. ),
  67. $this->orderValidator->validate(
  68. $order,
  69. [CanInvoice::class]
  70. )
  71. );
  72. }
  73. }