Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,38 @@ class AddressUpdate
*/
private $attribute;

/**
* Global configuration storage.
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $globalConfig;

/**
* AddressUpdate constructor.
* @param \Magento\Sales\Model\ResourceModel\GridPool $gridPool
* @param \Magento\Sales\Model\ResourceModel\Attribute $attribute
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
*/
public function __construct(
\Magento\Sales\Model\ResourceModel\GridPool $gridPool,
\Magento\Sales\Model\ResourceModel\Attribute $attribute
\Magento\Sales\Model\ResourceModel\Attribute $attribute,
\Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
) {
$this->gridPool = $gridPool;
$this->attribute = $attribute;
$this->globalConfig = $globalConfig;
}

/**
* Attach addresses to invoices
*
* @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $subject
* @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $result
* @param \Magento\Sales\Model\Order $order
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function afterProcess(
\Magento\Sales\Model\ResourceModel\Order\Handler\Address $subject,
Expand Down Expand Up @@ -68,8 +81,7 @@ public function afterProcess(
$this->attribute->saveAttribute($invoice, $invoiceAttributesForSave);
}
}

if ($orderInvoiceHasChanges) {
if ($orderInvoiceHasChanges && !$this->globalConfig->getValue('dev/grid/async_indexing')) {
$this->gridPool->refreshByOrderId($order->getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\Sales\Test\Unit\Model\Order\Invoice\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\Order\Invoice;
Expand Down Expand Up @@ -34,17 +35,27 @@ class AddressUpdateTest extends TestCase
*/
private $attributeMock;

/**
* @var MockObject
*/
private $globalConfigMock;

protected function setUp(): void
{
$this->gripPoolMock = $this->createMock(GridPool::class);
$this->attributeMock = $this->createMock(Attribute::class);
$this->globalConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->model = new AddressUpdate(
$this->gripPoolMock,
$this->attributeMock
$this->attributeMock,
$this->globalConfigMock
);
}

public function testAfterProcess()
/**
* @dataProvider dataProvider
*/
public function testAfterProcess($asyncReindexEnabled, $expectedReindexCalledCount)
{
$billingId = 100;
$shippingId = 200;
Expand All @@ -69,7 +80,9 @@ public function testAfterProcess()
$orderMock->expects($this->once())->method('getBillingAddress')->willReturn($billingMock);
$orderMock->expects($this->once())->method('getShippingAddress')->willReturn($shippingMock);
$orderMock->expects($this->once())->method('getInvoiceCollection')->willReturn($invoiceCollectionMock);
$orderMock->expects($this->once())->method('getId')->willReturn($orderId);
$orderMock->expects($this->exactly($expectedReindexCalledCount))
->method('getId')
->willReturn($orderId);

$invoiceMock->expects($this->once())->method('getBillingAddressId')->willReturn(null);
$invoiceMock->expects($this->once())->method('getShippingAddressId')->willReturn(null);
Expand All @@ -81,12 +94,34 @@ public function testAfterProcess()
->with($invoiceMock, ['billing_address_id', 'shipping_address_id'])
->willReturnSelf();

$this->gripPoolMock->expects($this->once())->method('refreshByOrderId')->with($orderId)->willReturnSelf();
$this->gripPoolMock->expects($this->exactly($expectedReindexCalledCount))
->method('refreshByOrderId')
->with($orderId)
->willReturnSelf();

$this->globalConfigMock->expects($this->once())
->method('getValue')
->with('dev/grid/async_indexing')
->willReturn($asyncReindexEnabled);

$this->model->afterProcess(
$this->createMock(\Magento\Sales\Model\ResourceModel\Order\Handler\Address::class),
$this->createMock(\Magento\Sales\Model\ResourceModel\Order\Handler\Address::class),
$orderMock
);
}

public function dataProvider()
{
return [
'Do not reindex when async is enabled' => [
true,
0
],
'Reindex when async is disabled' => [
false,
1
],
];
}
}