Skip to content

Commit 4b4b04b

Browse files
Yushkin, DmytroIevgen Sentiabov
authored andcommitted
MAGETWO-42841: Order cannot be placed via payment methods with Vitrual Product only
1 parent b94eaed commit 4b4b04b

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed

app/code/Magento/Payment/Gateway/Data/Order/OrderAdapter.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,33 @@ public function getCustomerId()
6969
/**
7070
* Returns billing address
7171
*
72-
* @return AddressAdapterInterface
72+
* @return AddressAdapterInterface|null
7373
*/
7474
public function getBillingAddress()
7575
{
76-
return $this->addressAdapterFactory->create(
77-
['address' => $this->order->getBillingAddress()]
78-
);
76+
if ($this->order->getBillingAddress()) {
77+
return $this->addressAdapterFactory->create(
78+
['address' => $this->order->getBillingAddress()]
79+
);
80+
}
81+
82+
return null;
7983
}
8084

8185
/**
8286
* Returns shipping address
8387
*
84-
* @return AddressAdapterInterface
88+
* @return AddressAdapterInterface|null
8589
*/
8690
public function getShippingAddress()
8791
{
88-
return $this->addressAdapterFactory->create(
89-
['address' => $this->order->getShippingAddress()]
90-
);
92+
if ($this->order->getShippingAddress()) {
93+
return $this->addressAdapterFactory->create(
94+
['address' => $this->order->getShippingAddress()]
95+
);
96+
}
97+
98+
return null;
9199
}
92100

93101
/**

app/code/Magento/Payment/Gateway/Data/OrderAdapterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public function getCustomerId();
3434
/**
3535
* Returns billing address
3636
*
37-
* @return AddressAdapterInterface
37+
* @return AddressAdapterInterface|null
3838
*/
3939
public function getBillingAddress();
4040

4141
/**
4242
* Returns shipping address
4343
*
44-
* @return AddressAdapterInterface
44+
* @return AddressAdapterInterface|null
4545
*/
4646
public function getShippingAddress();
4747

app/code/Magento/Payment/Gateway/Data/Quote/QuoteAdapter.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,33 @@ public function getCustomerId()
7070
/**
7171
* Returns billing address
7272
*
73-
* @return AddressAdapterInterface
73+
* @return AddressAdapterInterface|null
7474
*/
7575
public function getBillingAddress()
7676
{
77-
return $this->addressAdapterFactory->create(
78-
['address' => $this->quote->getBillingAddress()]
79-
);
77+
if ($this->quote->getBillingAddress()) {
78+
return $this->addressAdapterFactory->create(
79+
['address' => $this->quote->getBillingAddress()]
80+
);
81+
}
82+
83+
return null;
8084
}
8185

8286
/**
8387
* Returns shipping address
8488
*
85-
* @return AddressAdapterInterface
89+
* @return AddressAdapterInterface|null
8690
*/
8791
public function getShippingAddress()
8892
{
89-
return $this->addressAdapterFactory->create(
90-
['address' => $this->quote->getShippingAddress()]
91-
);
93+
if ($this->quote->getShippingAddress()) {
94+
return $this->addressAdapterFactory->create(
95+
['address' => $this->quote->getShippingAddress()]
96+
);
97+
}
98+
99+
return null;
92100
}
93101

94102
/**

app/code/Magento/Payment/Test/Unit/Gateway/Data/Order/OrderAdapterTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public function testGetCustomerId()
6262
$this->assertEquals($expected, $this->model->getCustomerId());
6363
}
6464

65+
public function testGetBillingAddressIsNull()
66+
{
67+
$this->orderMock->expects($this->once())->method('getBillingAddress')->willReturn(null);
68+
69+
$this->assertSame(null, $this->model->getBillingAddress());
70+
}
71+
6572
public function testGetBillingAddress()
6673
{
6774
/** @var AddressAdapterInterface $addressAdapterMock */
@@ -74,11 +81,18 @@ public function testGetBillingAddress()
7481
->method('create')
7582
->with(['address' => $orderAddressMock])
7683
->willReturn($addressAdapterMock);
77-
$this->orderMock->expects($this->once())->method('getBillingAddress')->willReturn($orderAddressMock);
84+
$this->orderMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($orderAddressMock);
7885

7986
$this->assertSame($addressAdapterMock, $this->model->getBillingAddress());
8087
}
8188

89+
public function testGetShippingAddressIsNull()
90+
{
91+
$this->orderMock->expects($this->once())->method('getShippingAddress')->willReturn(null);
92+
93+
$this->assertSame(null, $this->model->getShippingAddress());
94+
}
95+
8296
public function testGetShippingAddress()
8397
{
8498
/** @var AddressAdapterInterface $addressAdapterMock */
@@ -91,7 +105,7 @@ public function testGetShippingAddress()
91105
->method('create')
92106
->with(['address' => $orderAddressMock])
93107
->willReturn($addressAdapterMock);
94-
$this->orderMock->expects($this->once())->method('getShippingAddress')->willReturn($orderAddressMock);
108+
$this->orderMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($orderAddressMock);
95109

96110
$this->assertSame($addressAdapterMock, $this->model->getShippingAddress());
97111
}

app/code/Magento/Payment/Test/Unit/Gateway/Data/Quote/QuoteAdapterTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public function testGetCustomerId()
6868
$this->assertEquals($expected, $this->model->getCustomerId());
6969
}
7070

71+
public function testGetBillingAddressIsNull()
72+
{
73+
$this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(null);
74+
75+
$this->assertSame(null, $this->model->getBillingAddress());
76+
}
77+
7178
public function testGetBillingAddress()
7279
{
7380
/** @var AddressAdapterInterface $addressAdapterMock */
@@ -80,11 +87,18 @@ public function testGetBillingAddress()
8087
->method('create')
8188
->with(['address' => $quoteAddressMock])
8289
->willReturn($addressAdapterMock);
83-
$this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($quoteAddressMock);
90+
$this->quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($quoteAddressMock);
8491

8592
$this->assertSame($addressAdapterMock, $this->model->getBillingAddress());
8693
}
8794

95+
public function testGetShippingAddressIsNull()
96+
{
97+
$this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn(null);
98+
99+
$this->assertSame(null, $this->model->getShippingAddress());
100+
}
101+
88102
public function testGetShippingAddress()
89103
{
90104
/** @var AddressAdapterInterface $addressAdapterMock */
@@ -97,7 +111,7 @@ public function testGetShippingAddress()
97111
->method('create')
98112
->with(['address' => $quoteAddressMock])
99113
->willReturn($addressAdapterMock);
100-
$this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteAddressMock);
114+
$this->quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($quoteAddressMock);
101115

102116
$this->assertSame($addressAdapterMock, $this->model->getShippingAddress());
103117
}

0 commit comments

Comments
 (0)