-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Create cancel invoice method on API #12049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4a72b97
to
5e7ed2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider covering this with api-functional test as well
namespace Magento\Sales\Api; | ||
|
||
/** | ||
* Interface InvoiceCancelInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide description for the interface in the doc block.
It may be some information regarding it's responsibility and reasons for introduction.
/** | ||
* Interface InvoiceCancelInterface | ||
* | ||
* @package Magento\Sales\Api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@package
annotation is not used in Magento
* | ||
* @package Magento\Sales\Api | ||
*/ | ||
interface InvoiceCancelInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a good idea to mark this with @api
. This would also require providing PRs for other branches.
* @param int $invoiceId | ||
* @return bool | ||
*/ | ||
public function cancel($invoiceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR is targeting 2.2-develop
it is possible to declare scalar type hint and return type for the method.
public function cancel($invoiceId) | ||
{ | ||
/** @var \Magento\Sales\Api\Data\InvoiceInterface $invoice */ | ||
$invoice = $this->invoiceRepository->get($invoiceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method may throw an exception, which has to be either caught or declared in the interface.
{ | ||
/** @var \Magento\Sales\Api\Data\InvoiceInterface $invoice */ | ||
$invoice = $this->invoiceRepository->get($invoiceId); | ||
if ($invoice && $invoice->canCancel()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there is no reason to check for $invoice
variable, as repository would throw an exception or return an invoice, this variable would not be empty at this point.
Additionally, canCancel
check is already performed in the cancel
method implementation, is there ay particular reason for this?
/** | ||
* @var InvoiceRepositoryInterface | ||
*/ | ||
protected $invoiceRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid creating protected
properties in the core codebase, as usage of inheritance is discouraged.
if ($invoice && $invoice->canCancel()) { | ||
$invoice->cancel(); | ||
$this->invoiceRepository->save($invoice); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to return value of $invoice->getState()
here? This would allow to get rid of the if
statement.
@crissanclick I am closing this PR now due to inactivity. |
I have worked on this PR at #MM17ES
Description
Magento have not implemented cancel invoice method on API.
I have added the cancel method and created the tests.
Fixed Issues (if relevant)
Contribution checklist