Skip to content

Commit

Permalink
Merge forwardport of #11670 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11670.patch (created by @ajpevers) based on commit(s):
  1. cfd92c4
  2. 94ae23d
  3. 9145209
  4. ce20c0a
  5. 23f315c
  6. 72533ad
  7. 1d341ef
  8. f2ba426

Fixed GitHub Issues in 2.3-develop branch:
  - #11669: API salesRefundInvoiceV1 does no save invoice ID on credit memo (reported by @ajpevers)
  • Loading branch information
magento-engcom-team authored Jan 24, 2018
2 parents 8e77e2f + aefd089 commit 2d910df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions app/code/Magento/Sales/Model/Order/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
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\Model\AbstractModel;
use Magento\Sales\Model\EntityInterface;
use Magento\Sales\Model\Order\InvoiceFactory;

/**
* Order creditmemo model
Expand Down Expand Up @@ -112,6 +114,11 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt
*/
protected $priceCurrency;

/**
* @var InvoiceFactory
*/
private $invoiceFactory;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -128,6 +135,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 InvoiceFactory $invoiceFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -145,7 +153,8 @@ public function __construct(
PriceCurrencyInterface $priceCurrency,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
InvoiceFactory $invoiceFactory = null
) {
$this->_creditmemoConfig = $creditmemoConfig;
$this->_orderFactory = $orderFactory;
Expand All @@ -155,6 +164,7 @@ public function __construct(
$this->_commentFactory = $commentFactory;
$this->_commentCollectionFactory = $commentCollectionFactory;
$this->priceCurrency = $priceCurrency;
$this->invoiceFactory = $invoiceFactory ?: ObjectManager::getInstance()->get(InvoiceFactory::class);
parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -377,6 +387,9 @@ public function canRefund()
*/
public function getInvoice()
{
if (!$this->getData('invoice') instanceof \Magento\Sales\Api\Data\InvoiceInterface && $this->getInvoiceId()) {
$this->setInvoice($this->invoiceFactory->create()->load($this->getInvoiceId()));
}
return $this->getData('invoice');
}

Expand Down Expand Up @@ -1505,6 +1518,5 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\CreditmemoExtensi
{
return $this->_setExtensionAttributes($extensionAttributes);
}

//@codeCoverageIgnoreEnd
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
$object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId());
}

if (!$object->getInvoiceId() && $object->getInvoice()) {
$object->setInvoiceId($object->getInvoice()->getId());
}

return parent::_beforeSave($object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testProcessIpnRequestPartialRefund()
/**
* Refund rest of order amount by Paypal Express IPN message service.
*
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_creditmemo.php
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_shipping.php
* @magentoConfigFixture current_store payment/paypal_express/active 1
* @magentoConfigFixture current_store paypal/general/merchant_country US
*/
Expand All @@ -147,7 +147,7 @@ public function testProcessIpnRequestRestRefund()
$creditmemoItems = $order->getCreditmemosCollection()->getItems();

$this->assertEquals(Order::STATE_CLOSED, $order->getState()) ;
$this->assertEquals(2, count($creditmemoItems));
$this->assertEquals(1, count($creditmemoItems));
$this->assertEquals(10, $order->getSubtotalRefunded());
$this->assertEquals(10, $order->getBaseSubtotalRefunded());
$this->assertEquals(20, $order->getShippingRefunded());
Expand Down

0 comments on commit 2d910df

Please sign in to comment.