Skip to content

Fix shipping address id getter misspelling #28810

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

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 @@ -9,9 +9,6 @@
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Attribute;

/**
* Class Address
*/
class Address
{
/**
Expand Down Expand Up @@ -69,7 +66,7 @@ public function process(Order $order)
$attributesForSave[] = 'billing_address_id';
}
$shippingAddress = $order->getShippingAddress();
if ($shippingAddress && $order->getShippigAddressId() != $shippingAddress->getId()) {
if ($shippingAddress && $order->getShippingAddressId() != $shippingAddress->getId()) {
$order->setShippingAddressId($shippingAddress->getId());
$attributesForSave[] = 'shipping_address_id';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,66 @@ public function testProcessShippingAddress()
$this->assertEquals($this->address, $this->address->process($this->orderMock));
}

/**
* Test processing of the shipping address when shipping address id was not changed.
* setShippingAddressId and saveAttribute methods must not be executed.
*/
public function testProcessShippingAddressNotChanged()
{
$this->orderMock->expects($this->exactly(2))
->method('getAddresses')
->willReturn([$this->addressMock]);
$this->addressMock->expects($this->once())
->method('save')->willReturnSelf();
$this->orderMock->expects($this->once())
->method('getBillingAddress')
->willReturn(null);
$this->orderMock->expects($this->once())
->method('getShippingAddress')
->willReturn($this->addressMock);
$this->addressMock->expects($this->once())
->method('getId')->willReturn(1);
$this->orderMock->expects($this->once())
->method('getShippingAddressId')
->willReturn(1);
$this->orderMock->expects($this->never())
->method('setShippingAddressId')->willReturnSelf();
$this->attributeMock->expects($this->never())
->method('saveAttribute')
->with($this->orderMock, ['shipping_address_id'])->willReturnSelf();
$this->assertEquals($this->address, $this->address->process($this->orderMock));
}

/**
* Test processing of the billing address when billing address id was not changed.
* setBillingAddressId and saveAttribute methods must not be executed.
*/
public function testProcessBillingAddressNotChanged()
{
$this->orderMock->expects($this->exactly(2))
->method('getAddresses')
->willReturn([$this->addressMock]);
$this->addressMock->expects($this->once())
->method('save')->willReturnSelf();
$this->orderMock->expects($this->once())
->method('getBillingAddress')
->willReturn($this->addressMock);
$this->orderMock->expects($this->once())
->method('getShippingAddress')
->willReturn(null);
$this->addressMock->expects($this->once())
->method('getId')->willReturn(1);
$this->orderMock->expects($this->once())
->method('getBillingAddressId')
->willReturn(1);
$this->orderMock->expects($this->never())
->method('setBillingAddressId')->willReturnSelf();
$this->attributeMock->expects($this->never())
->method('saveAttribute')
->with($this->orderMock, ['billing_address_id'])->willReturnSelf();
$this->assertEquals($this->address, $this->address->process($this->orderMock));
}

/**
* Test method removeEmptyAddresses
*/
Expand Down