Skip to content

Commit 6a4d473

Browse files
committed
MAGETWO-55657: Implement new service OrderInvoice
- fix statics
1 parent 83b48ec commit 6a4d473

File tree

11 files changed

+81
-58
lines changed

11 files changed

+81
-58
lines changed

app/code/Magento/Sales/Api/CouldNotInvoiceException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Sales\Api;
87

98
use Magento\Framework\Exception\LocalizedException;

app/code/Magento/Sales/Api/DocumentValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Sales\Api;
87

98
use Magento\Framework\Exception\LocalizedException;
@@ -14,4 +13,5 @@
1413
*/
1514
class DocumentValidationException extends LocalizedException
1615
{
16+
1717
}
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
<?php
2-
/**
3-
* Copyright © 2016 Magento. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
7-
namespace Magento\Sales\Model\Order\Invoice;
8-
9-
/**
10-
* Interface for Invoice notifier.
11-
*
12-
* @api
13-
*/
14-
interface NotifierInterface
15-
{
16-
/**
17-
* Notifies customer.
18-
*
19-
* @param \Magento\Sales\Api\Data\OrderInterface $order
20-
* @param \Magento\Sales\Api\Data\InvoiceInterface $invoice
21-
* @param \Magento\Sales\Api\Data\InvoiceCommentCreationInterface|null $comment
22-
* @param bool $forceSyncMode
23-
*
24-
* @return void
25-
*/
26-
public function notify(
27-
\Magento\Sales\Api\Data\OrderInterface $order,
28-
\Magento\Sales\Api\Data\InvoiceInterface $invoice,
29-
\Magento\Sales\Api\Data\InvoiceCommentCreationInterface $comment = null,
30-
$forceSyncMode = false
31-
);
32-
}
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\Order\Invoice;
8+
9+
/**
10+
* Interface for Invoice notifier.
11+
*
12+
* @api
13+
*/
14+
interface NotifierInterface
15+
{
16+
/**
17+
* Notifies customer.
18+
*
19+
* @param \Magento\Sales\Api\Data\OrderInterface $order
20+
* @param \Magento\Sales\Api\Data\InvoiceInterface $invoice
21+
* @param \Magento\Sales\Api\Data\InvoiceCommentCreationInterface|null $comment
22+
* @param bool $forceSyncMode
23+
*
24+
* @return void
25+
*/
26+
public function notify(
27+
\Magento\Sales\Api\Data\OrderInterface $order,
28+
\Magento\Sales\Api\Data\InvoiceInterface $invoice,
29+
\Magento\Sales\Api\Data\InvoiceCommentCreationInterface $comment = null,
30+
$forceSyncMode = false
31+
);
32+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(
4242
* @param bool|false $appendComment
4343
* @param InvoiceCreationArgumentsInterface|null $arguments
4444
* @return InvoiceInterface
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4546
*/
4647
public function create(
4748
OrderInterface $order,

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public function validate(InvoiceInterface $invoice, OrderInterface $order)
5757
private function checkQtyAvailability(InvoiceInterface $invoice, OrderInterface $order)
5858
{
5959
$messages = [];
60-
$qtys = [];
61-
/** @var InvoiceItemInterface $item */
62-
foreach ($invoice->getItems() as $item) {
63-
$qtys[$item->getOrderItemId()] = $item->getQty();
64-
}
60+
$qtys = $this->getInvoiceQty($invoice);
6561

6662
$totalQty = 0;
6763
if ($qtys) {
@@ -71,21 +67,34 @@ private function checkQtyAvailability(InvoiceInterface $invoice, OrderInterface
7167
if ($qtys[$orderItem->getId()] > $orderItem->getQtyToInvoice() && !$orderItem->isDummy()) {
7268
$messages[] = __(
7369
'The quantity to invoice must not be greater than the uninvoiced quantity'
74-
. ' for product SKU "%1".',
70+
. ' for product SKU "%1".',
7571
$orderItem->getSku()
7672
);
7773
}
7874
$totalQty += $qtys[$orderItem->getId()];
7975
unset($qtys[$orderItem->getId()]);
8076
}
8177
}
82-
if ($qtys) {
83-
$messages[] = __('The invoice contains one or more items that are not part of the original order.');
84-
}
8578
}
86-
if (!$qtys && $totalQty <= 0) {
79+
if ($qtys) {
80+
$messages[] = __('The invoice contains one or more items that are not part of the original order.');
81+
} elseif ($totalQty <= 0) {
8782
$messages[] = __('You can\'t create an invoice without products.');
8883
}
8984
return $messages;
9085
}
86+
87+
/**
88+
* @param InvoiceInterface $invoice
89+
* @return array
90+
*/
91+
private function getInvoiceQty(InvoiceInterface $invoice)
92+
{
93+
$qtys = [];
94+
/** @var InvoiceItemInterface $item */
95+
foreach ($invoice->getItems() as $item) {
96+
$qtys[$item->getOrderItemId()] = $item->getQty();
97+
}
98+
return $qtys;
99+
}
91100
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ public function execute(
152152
);
153153
$errorMessages = $this->invoiceValidator->validate($invoice, $order);
154154
if (!empty($errorMessages)) {
155-
throw new DocumentValidationException(__(
156-
"Invoice Document Validation Error(s):\n" . implode("\n", $errorMessages))
155+
throw new DocumentValidationException(
156+
__("Invoice Document Validation Error(s):\n" . implode("\n", $errorMessages))
157157
);
158158
}
159159
$connection->beginTransaction();
@@ -163,7 +163,7 @@ public function execute(
163163
$this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
164164
);
165165
$order->setStatus($this->config->getStateDefaultStatus($order->getState()));
166-
$invoice->setState(InvoiceInterface::STATE_PAID);
166+
$invoice->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID);
167167
$this->invoiceRepository->save($invoice);
168168
$this->orderRepository->save($order);
169169
$connection->commit();

app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/PayOperationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class PayOperationTest extends \PHPUnit_Framework_TestCase
5050
*/
5151
private $paymentMethodMock;
5252

53+
/**
54+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
55+
*/
5356
protected function setUp()
5457
{
5558
$this->orderMock = $this->getMockForAbstractClass(
@@ -299,6 +302,7 @@ protected function setUp()
299302
* @dataProvider payDataProvider
300303
*
301304
* @return void
305+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
302306
*/
303307
public function testExecute($canCapture, $isOnline, $isGateway, $isTransactionPending)
304308
{

app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php

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

88
/**
99
* Unit test for email notification sender for Invoice.
10+
* @SuppressWarnings(PHPMD.TooManyFields)
11+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1012
*/
1113
class EmailSenderTest extends \PHPUnit_Framework_TestCase
1214
{
@@ -95,6 +97,9 @@ class EmailSenderTest extends \PHPUnit_Framework_TestCase
9597
*/
9698
private $senderBuilderFactoryMock;
9799

100+
/**
101+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
102+
*/
98103
protected function setUp()
99104
{
100105
$this->orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
@@ -188,21 +193,21 @@ protected function setUp()
188193
->getMock();
189194

190195
$this->identityContainerMock = $this->getMockBuilder(
191-
\Magento\Sales\Model\Order\Email\Container\InvoiceIdentity::class
192-
)
193-
->disableOriginalConstructor()
194-
->getMock();
196+
\Magento\Sales\Model\Order\Email\Container\InvoiceIdentity::class
197+
)
198+
->disableOriginalConstructor()
199+
->getMock();
195200

196201
$this->identityContainerMock->expects($this->any())
197202
->method('getStore')
198203
->willReturn($this->storeMock);
199204

200205
$this->senderBuilderFactoryMock = $this->getMockBuilder(
201206
\Magento\Sales\Model\Order\Email\SenderBuilderFactory::class
202-
)
203-
->disableOriginalConstructor()
204-
->setMethods(['create'])
205-
->getMock();
207+
)
208+
->disableOriginalConstructor()
209+
->setMethods(['create'])
210+
->getMock();
206211

207212
$this->subject = new \Magento\Sales\Model\Order\Invoice\Sender\EmailSender(
208213
$this->templateContainerMock,
@@ -226,6 +231,7 @@ protected function setUp()
226231
* @dataProvider sendDataProvider
227232
*
228233
* @return void
234+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
229235
*/
230236
public function testSend($configValue, $forceSyncMode, $isComment, $emailSendingResult)
231237
{

app/code/Magento/Sales/Test/Unit/Model/Order/StateResolverTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public function testStateProcessing()
7474
->method('getState')
7575
->willReturn(Order::STATE_NEW);
7676

77-
$this->assertEquals(Order::STATE_PROCESSING, $this->orderStateResolver->getStateForOrder($this->orderMock, $arguments));
77+
$this->assertEquals(
78+
Order::STATE_PROCESSING,
79+
$this->orderStateResolver->getStateForOrder($this->orderMock, $arguments)
80+
);
7881
}
7982
}

app/code/Magento/Sales/Test/Unit/Model/OrderInvoiceTest.php

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

2626
/**
2727
* Class OrderInvoiceTest
28+
* @SuppressWarnings(PHPMD.TooManyFields)
2829
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2930
*/
3031
class OrderInvoiceTest extends \PHPUnit_Framework_TestCase
@@ -245,7 +246,7 @@ public function testOrderInvoice($orderId, $capture, $items, $notify, $appendCom
245246

246247
$this->invoiceMock->expects($this->once())
247248
->method('setState')
248-
->with(InvoiceInterface::STATE_PAID)
249+
->with(\Magento\Sales\Model\Order\Invoice::STATE_PAID)
249250
->willReturnSelf();
250251

251252
$this->invoiceRepositoryMock->expects($this->once())

0 commit comments

Comments
 (0)