Skip to content

Commit 8a60fa5

Browse files
author
Olexandr Lysenko
committed
Merge branch 'MAGETWO-54693' into bugfixes
2 parents 1f11f82 + b8a0a40 commit 8a60fa5

File tree

53 files changed

+3009
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3009
-521
lines changed

app/code/Magento/Sales/Model/InvoiceOrder.php

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
use Magento\Sales\Api\InvoiceOrderInterface;
1313
use Magento\Sales\Api\OrderRepositoryInterface;
1414
use Magento\Sales\Model\Order\Config as OrderConfig;
15-
use Magento\Sales\Model\Order\Invoice\InvoiceValidatorInterface;
1615
use Magento\Sales\Model\Order\Invoice\NotifierInterface;
1716
use Magento\Sales\Model\Order\InvoiceDocumentFactory;
18-
use Magento\Sales\Model\Order\InvoiceQuantityValidator;
1917
use Magento\Sales\Model\Order\InvoiceRepository;
2018
use Magento\Sales\Model\Order\OrderStateResolverInterface;
21-
use Magento\Sales\Model\Order\OrderValidatorInterface;
2219
use Magento\Sales\Model\Order\PaymentAdapterInterface;
23-
use Magento\Sales\Model\Order\Validation\CanInvoice;
20+
use Magento\Sales\Model\Order\Validation\InvoiceOrderInterface as InvoiceOrderValidator;
2421
use Psr\Log\LoggerInterface;
2522

2623
/**
@@ -44,11 +41,6 @@ class InvoiceOrder implements InvoiceOrderInterface
4441
*/
4542
private $invoiceDocumentFactory;
4643

47-
/**
48-
* @var InvoiceValidatorInterface
49-
*/
50-
private $invoiceValidator;
51-
5244
/**
5345
* @var PaymentAdapterInterface
5446
*/
@@ -69,6 +61,11 @@ class InvoiceOrder implements InvoiceOrderInterface
6961
*/
7062
private $invoiceRepository;
7163

64+
/**
65+
* @var InvoiceOrderValidator
66+
*/
67+
private $invoiceOrderValidator;
68+
7269
/**
7370
* @var NotifierInterface
7471
*/
@@ -80,21 +77,15 @@ class InvoiceOrder implements InvoiceOrderInterface
8077
private $logger;
8178

8279
/**
83-
* @var OrderValidatorInterface
84-
*/
85-
private $orderValidator;
86-
87-
/**
88-
* OrderInvoice constructor.
80+
* InvoiceOrder constructor.
8981
* @param ResourceConnection $resourceConnection
9082
* @param OrderRepositoryInterface $orderRepository
9183
* @param InvoiceDocumentFactory $invoiceDocumentFactory
92-
* @param InvoiceValidatorInterface $invoiceValidator
93-
* @param OrderValidatorInterface $orderValidator
9484
* @param PaymentAdapterInterface $paymentAdapter
9585
* @param OrderStateResolverInterface $orderStateResolver
9686
* @param OrderConfig $config
9787
* @param InvoiceRepository $invoiceRepository
88+
* @param InvoiceOrderValidator $invoiceOrderValidator
9889
* @param NotifierInterface $notifierInterface
9990
* @param LoggerInterface $logger
10091
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -103,24 +94,22 @@ public function __construct(
10394
ResourceConnection $resourceConnection,
10495
OrderRepositoryInterface $orderRepository,
10596
InvoiceDocumentFactory $invoiceDocumentFactory,
106-
InvoiceValidatorInterface $invoiceValidator,
107-
OrderValidatorInterface $orderValidator,
10897
PaymentAdapterInterface $paymentAdapter,
10998
OrderStateResolverInterface $orderStateResolver,
11099
OrderConfig $config,
111100
InvoiceRepository $invoiceRepository,
101+
InvoiceOrderValidator $invoiceOrderValidator,
112102
NotifierInterface $notifierInterface,
113103
LoggerInterface $logger
114104
) {
115105
$this->resourceConnection = $resourceConnection;
116106
$this->orderRepository = $orderRepository;
117107
$this->invoiceDocumentFactory = $invoiceDocumentFactory;
118-
$this->invoiceValidator = $invoiceValidator;
119-
$this->orderValidator = $orderValidator;
120108
$this->paymentAdapter = $paymentAdapter;
121109
$this->orderStateResolver = $orderStateResolver;
122110
$this->config = $config;
123111
$this->invoiceRepository = $invoiceRepository;
112+
$this->invoiceOrderValidator = $invoiceOrderValidator;
124113
$this->notifierInterface = $notifierInterface;
125114
$this->logger = $logger;
126115
}
@@ -158,19 +147,19 @@ public function execute(
158147
($appendComment && $notify),
159148
$arguments
160149
);
161-
$errorMessages = array_merge(
162-
$this->invoiceValidator->validate(
163-
$invoice,
164-
[InvoiceQuantityValidator::class]
165-
),
166-
$this->orderValidator->validate(
167-
$order,
168-
[CanInvoice::class]
169-
)
150+
$errorMessages = $this->invoiceOrderValidator->validate(
151+
$order,
152+
$invoice,
153+
$capture,
154+
$items,
155+
$notify,
156+
$appendComment,
157+
$comment,
158+
$arguments
170159
);
171-
if (!empty($errorMessages)) {
160+
if ($errorMessages->hasMessages()) {
172161
throw new \Magento\Sales\Exception\DocumentValidationException(
173-
__("Invoice Document Validation Error(s):\n" . implode("\n", $errorMessages))
162+
__("Invoice Document Validation Error(s):\n" . implode("\n", $errorMessages->getMessages()))
174163
);
175164
}
176165
$connection->beginTransaction();

app/code/Magento/Sales/Model/Order/Creditmemo/CreditmemoValidatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Sales\Api\Data\CreditmemoInterface;
99
use Magento\Sales\Exception\DocumentValidationException;
1010
use Magento\Sales\Model\ValidatorInterface;
11+
use Magento\Sales\Model\ValidatorResultInterface;
1112

1213
/**
1314
* Interface CreditmemoValidatorInterface
@@ -17,7 +18,7 @@ interface CreditmemoValidatorInterface
1718
/**
1819
* @param CreditmemoInterface $entity
1920
* @param ValidatorInterface[] $validators
20-
* @return string[]
21+
* @return ValidatorResultInterface
2122
* @throws DocumentValidationException
2223
*/
2324
public function validate(CreditmemoInterface $entity, array $validators);

app/code/Magento/Sales/Model/Order/Creditmemo/ItemCreationValidatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Sales\Api\Data\CreditmemoItemCreationInterface;
99
use Magento\Sales\Api\Data\OrderInterface;
10+
use Magento\Sales\Model\ValidatorResultInterface;
1011

1112
/**
1213
* Interface ItemCreationValidatorInterface
@@ -17,7 +18,7 @@ interface ItemCreationValidatorInterface
1718
* @param CreditmemoItemCreationInterface $item
1819
* @param array $validators
1920
* @param OrderInterface|null $context
20-
* @return mixed
21+
* @return ValidatorResultInterface
2122
*/
2223
public function validate(CreditmemoItemCreationInterface $item, array $validators, OrderInterface $context = null);
2324
}

app/code/Magento/Sales/Model/Order/CreditmemoDocumentFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Class CreditmemoDocumentFactory
10+
*
11+
* @api
1012
*/
1113
class CreditmemoDocumentFactory
1214
{

app/code/Magento/Sales/Model/Order/Invoice/InvoiceValidatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Sales\Api\Data\InvoiceInterface;
99
use Magento\Sales\Exception\DocumentValidationException;
1010
use Magento\Sales\Model\ValidatorInterface;
11+
use Magento\Sales\Model\ValidatorResultInterface;
1112

1213
/**
1314
* Interface InvoiceValidatorInterface
@@ -17,7 +18,7 @@ interface InvoiceValidatorInterface
1718
/**
1819
* @param InvoiceInterface $entity
1920
* @param ValidatorInterface[] $validators
20-
* @return string[]
21+
* @return ValidatorResultInterface
2122
* @throws DocumentValidationException
2223
*/
2324
public function validate(InvoiceInterface $entity, array $validators);

app/code/Magento/Sales/Model/Order/OrderValidatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Sales\Api\Data\OrderInterface;
99
use Magento\Sales\Exception\DocumentValidationException;
1010
use Magento\Sales\Model\ValidatorInterface;
11+
use Magento\Sales\Model\ValidatorResultInterface;
1112

1213
/**
1314
* Interface OrderValidatorInterface
@@ -17,7 +18,7 @@ interface OrderValidatorInterface
1718
/**
1819
* @param OrderInterface $entity
1920
* @param ValidatorInterface[] $validators
20-
* @return string[]
21+
* @return ValidatorResultInterface
2122
* @throws DocumentValidationException
2223
*/
2324
public function validate(OrderInterface $entity, array $validators);

app/code/Magento/Sales/Model/Order/Shipment/ShipmentValidatorInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Sales\Api\Data\ShipmentInterface;
99
use Magento\Sales\Exception\DocumentValidationException;
1010
use Magento\Sales\Model\ValidatorInterface;
11+
use Magento\Sales\Model\ValidatorResultInterface;
1112

1213
/**
1314
* Interface ShipmentValidatorInterface
@@ -17,7 +18,7 @@ interface ShipmentValidatorInterface
1718
/**
1819
* @param ShipmentInterface $shipment
1920
* @param ValidatorInterface[] $validators
20-
* @return string[]
21+
* @return ValidatorResultInterface
2122
* @throws DocumentValidationException
2223
*/
2324
public function validate(ShipmentInterface $shipment, array $validators);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Model\Order\Validation;
7+
8+
use Magento\Sales\Api\Data\InvoiceCommentCreationInterface;
9+
use Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface;
10+
use Magento\Sales\Api\Data\InvoiceInterface;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
use Magento\Sales\Model\Order\Invoice\InvoiceValidatorInterface;
13+
use Magento\Sales\Model\Order\InvoiceQuantityValidator;
14+
use Magento\Sales\Model\Order\OrderValidatorInterface;
15+
use Magento\Sales\Model\ValidatorResultInterface;
16+
use Magento\Sales\Model\ValidatorResultMerger;
17+
18+
/**
19+
* Class InvoiceOrder
20+
* Validation for invoice order operation
21+
*/
22+
class InvoiceOrder implements InvoiceOrderInterface
23+
{
24+
/**
25+
* @var InvoiceValidatorInterface
26+
*/
27+
private $invoiceValidator;
28+
29+
/**
30+
* @var OrderValidatorInterface
31+
*/
32+
private $orderValidator;
33+
34+
/**
35+
* @var ValidatorResultMerger
36+
*/
37+
private $validatorResultMerger;
38+
39+
/**
40+
* InvoiceOrder constructor.
41+
* @param InvoiceValidatorInterface $invoiceValidator
42+
* @param OrderValidatorInterface $orderValidator
43+
* @param ValidatorResultMerger $validatorResultMerger
44+
*/
45+
public function __construct(
46+
InvoiceValidatorInterface $invoiceValidator,
47+
OrderValidatorInterface $orderValidator,
48+
ValidatorResultMerger $validatorResultMerger
49+
) {
50+
$this->invoiceValidator = $invoiceValidator;
51+
$this->orderValidator = $orderValidator;
52+
$this->validatorResultMerger = $validatorResultMerger;
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function validate(
59+
OrderInterface $order,
60+
InvoiceInterface $invoice,
61+
$capture = false,
62+
array $items = [],
63+
$notify = false,
64+
$appendComment = false,
65+
InvoiceCommentCreationInterface $comment = null,
66+
InvoiceCreationArgumentsInterface $arguments = null
67+
) {
68+
return $this->validatorResultMerger->merge(
69+
$this->invoiceValidator->validate(
70+
$invoice,
71+
[InvoiceQuantityValidator::class]
72+
),
73+
$this->orderValidator->validate(
74+
$order,
75+
[CanInvoice::class]
76+
)
77+
);
78+
}
79+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Model\Order\Validation;
7+
8+
use Magento\Sales\Api\Data\InvoiceCommentCreationInterface;
9+
use Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface;
10+
use Magento\Sales\Api\Data\InvoiceInterface;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
use Magento\Sales\Model\ValidatorResultInterface;
13+
14+
/**
15+
* Interface InvoiceOrderInterface
16+
*
17+
* @api
18+
*/
19+
interface InvoiceOrderInterface
20+
{
21+
/**
22+
* @param OrderInterface $order
23+
* @param InvoiceInterface $invoice
24+
* @param bool $capture
25+
* @param array $items
26+
* @param bool $notify
27+
* @param bool $appendComment
28+
* @param InvoiceCommentCreationInterface|null $comment
29+
* @param InvoiceCreationArgumentsInterface|null $arguments
30+
* @return ValidatorResultInterface
31+
*/
32+
public function validate(
33+
OrderInterface $order,
34+
InvoiceInterface $invoice,
35+
$capture = false,
36+
array $items = [],
37+
$notify = false,
38+
$appendComment = false,
39+
InvoiceCommentCreationInterface $comment = null,
40+
InvoiceCreationArgumentsInterface $arguments = null
41+
);
42+
}

0 commit comments

Comments
 (0)