-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
save invoice ID on credit memo when using API method salesRefundInvoiceV1 #11670
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cfd92c4
save invoice ID on credit memo when using API method salesRefundInvoi…
94ae23d
Move deprecated method logic to constructor
9145209
Replace call to removed method
ce20c0a
Refactor invoice id persistance and retrieval to be more like the get…
23f315c
Fix IpnTest
72533ad
specify the correct invoice factory
1d341ef
use InvoiceInterface instead of Invoice model to check if an invoice …
f2ba426
magento/magento2#11670: Merge branch '2.2-develop' of github.com:mage…
ishakhsuvarov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,10 @@ | |
namespace Magento\Sales\Model\Order; | ||
|
||
use Magento\Framework\Api\AttributeValueFactory; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\Pricing\PriceCurrencyInterface; | ||
use Magento\Sales\Api\Data\CreditmemoInterface; | ||
use Magento\Sales\Api\InvoiceRepositoryInterface; | ||
use Magento\Sales\Model\AbstractModel; | ||
use Magento\Sales\Model\EntityInterface; | ||
|
||
|
@@ -114,6 +116,11 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt | |
*/ | ||
protected $priceCurrency; | ||
|
||
/** | ||
* @var InvoiceRepository | ||
*/ | ||
private $invoiceRepository; | ||
|
||
/** | ||
* @param \Magento\Framework\Model\Context $context | ||
* @param \Magento\Framework\Registry $registry | ||
|
@@ -130,6 +137,7 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt | |
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource | ||
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection | ||
* @param array $data | ||
* @param InvoiceRepository $invoiceRepository | ||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||
*/ | ||
public function __construct( | ||
|
@@ -147,7 +155,8 @@ public function __construct( | |
PriceCurrencyInterface $priceCurrency, | ||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, | ||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
array $data = [], | ||
InvoiceRepository $invoiceRepository = null | ||
) { | ||
$this->_creditmemoConfig = $creditmemoConfig; | ||
$this->_orderFactory = $orderFactory; | ||
|
@@ -157,6 +166,7 @@ public function __construct( | |
$this->_commentFactory = $commentFactory; | ||
$this->_commentCollectionFactory = $commentCollectionFactory; | ||
$this->priceCurrency = $priceCurrency; | ||
$this->invoiceRepository = $invoiceRepository; | ||
parent::__construct( | ||
$context, | ||
$registry, | ||
|
@@ -379,6 +389,9 @@ public function canRefund() | |
*/ | ||
public function getInvoice() | ||
{ | ||
if (!$this->getData('invoice') instanceof \Magento\Sales\Model\Order\Invoice && $this->getInvoiceId()) { | ||
$this->setInvoice($this->getInvoiceRepository()->get($this->getInvoiceId())); | ||
} | ||
return $this->getData('invoice'); | ||
} | ||
|
||
|
@@ -391,6 +404,7 @@ public function getInvoice() | |
public function setInvoice(Invoice $invoice) | ||
{ | ||
$this->setData('invoice', $invoice); | ||
$this->setInvoiceId($invoice->getId()); | ||
return $this; | ||
} | ||
|
||
|
@@ -1525,5 +1539,12 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\CreditmemoExtensi | |
return $this->_setExtensionAttributes($extensionAttributes); | ||
} | ||
|
||
/** | ||
* @return InvoiceRepositoryInterface|mixed | ||
* @deprecated | ||
*/ | ||
private function getInvoiceRepository() { | ||
return $this->invoiceRepository ?: ObjectManager::getInstance()->get(InvoiceRepositoryInterface::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid such methods creation and move this logic to constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay |
||
} | ||
//@codeCoverageIgnoreEnd | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 there a reason not to use
\Magento\Sales\Api\Data\InvoiceInterface
here?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.
Good point. No there is no reason.