Skip to content

Commit 22fcfa8

Browse files
author
Kostiantyn Poida
committed
MAGETWO-15874: Edit button is present when order is already captured
1 parent 9c19d10 commit 22fcfa8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ public function canEdit()
801801
return false;
802802
}
803803

804+
if ($this->hasInvoices()) {
805+
return false;
806+
}
807+
804808
if (!$this->getPayment()->getMethodInstance()->canEdit()) {
805809
return false;
806810
}
@@ -1820,6 +1824,18 @@ public function getInvoiceCollection()
18201824
return $this->_invoices;
18211825
}
18221826

1827+
/**
1828+
* Set order invoices collection
1829+
*
1830+
* @param InvoiceCollection $invoices
1831+
* @return $this
1832+
*/
1833+
public function setInvoiceCollection(InvoiceCollection $invoices)
1834+
{
1835+
$this->_invoices = $invoices;
1836+
return $this;
1837+
}
1838+
18231839
/**
18241840
* Retrieve order shipments collection
18251841
*

dev/tests/unit/testsuite/Magento/Sales/Model/OrderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ public function testCanCancelIsPaymentReview()
191191
$this->assertFalse($this->order->canCancel());
192192
}
193193

194+
public function testCanEditIfHasInvoices()
195+
{
196+
$invoiceCollection = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Invoice\Collection')
197+
->disableOriginalConstructor()
198+
->setMethods(['count'])
199+
->getMock();
200+
201+
$invoiceCollection->expects($this->once())
202+
->method('count')
203+
->willReturn(2);
204+
205+
$this->order->setInvoiceCollection($invoiceCollection);
206+
$this->order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING);
207+
208+
$this->assertFalse($this->order->canEdit());
209+
}
210+
194211
public function testCanCancelCanReviewPayment()
195212
{
196213
$paymentMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Payment')

0 commit comments

Comments
 (0)