Skip to content

Commit 245737c

Browse files
committed
ACP2E-3028: Paylater message not showing in PDP for Canadian paypal merchant account
1 parent 57c19b9 commit 245737c

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

app/code/Magento/Paypal/CustomerData/BuyerCountry.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Magento\Paypal\CustomerData;
1212

13-
use Magento\Customer\Api\AddressRepositoryInterface;
1413
use Magento\Customer\CustomerData\SectionSourceInterface;
1514
use Magento\Customer\Helper\Session\CurrentCustomer;
1615
use Magento\Framework\Exception\NoSuchEntityException;
@@ -19,12 +18,9 @@ class BuyerCountry implements SectionSourceInterface
1918
{
2019
/**
2120
* @param CurrentCustomer $currentCustomer
22-
* @param AddressRepositoryInterface $addressRepository
2321
*/
24-
public function __construct(
25-
private readonly CurrentCustomer $currentCustomer,
26-
private readonly AddressRepositoryInterface $addressRepository
27-
) {
22+
public function __construct(private readonly CurrentCustomer $currentCustomer)
23+
{
2824
}
2925

3026
/**
@@ -40,8 +36,12 @@ public function getSectionData()
4036
$customer->getDefaultShipping();
4137

4238
if ($addressId) {
43-
$address = $this->addressRepository->getById($addressId);
44-
$country = $address->getCountryId();
39+
foreach ($customer->getAddresses() as $address) {
40+
if ($address->getId() == $addressId) {
41+
$country = $address->getCountryId();
42+
break;
43+
}
44+
}
4545
}
4646
} catch (NoSuchEntityException $e) {
4747
return [

app/code/Magento/Paypal/Test/Unit/CustomerData/BuyerCountryTest.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Magento\Paypal\Test\Unit\CustomerData;
1212

13-
use Magento\Customer\Api\AddressRepositoryInterface;
1413
use Magento\Customer\Api\Data\AddressInterface;
1514
use Magento\Customer\Api\Data\CustomerInterface;
1615
use Magento\Customer\Helper\Session\CurrentCustomer;
@@ -26,11 +25,6 @@ class BuyerCountryTest extends TestCase
2625
*/
2726
private CurrentCustomer $currentCustomer;
2827

29-
/**
30-
* @var AddressRepositoryInterface|MockObject
31-
*/
32-
private AddressRepositoryInterface $addressRepository;
33-
3428
/**
3529
* @var BuyerCountry
3630
*/
@@ -42,25 +36,17 @@ class BuyerCountryTest extends TestCase
4236
protected function setUp(): void
4337
{
4438
$this->currentCustomer = $this->createMock(CurrentCustomer::class);
45-
$this->addressRepository = $this->createMock(AddressRepositoryInterface::class);
4639

47-
$this->buyerCountry = new BuyerCountry($this->currentCustomer, $this->addressRepository);
40+
$this->buyerCountry = new BuyerCountry($this->currentCustomer);
4841
}
4942

5043
/**
5144
* @return void
5245
*/
5346
public function testGetSectionDataException(): void
5447
{
55-
$customer = $this->createMock(CustomerInterface::class);
56-
$customer->expects($this->exactly(2))
57-
->method('getDefaultBilling')
58-
->willReturn(1);
5948
$this->currentCustomer->expects($this->once())
6049
->method('getCustomer')
61-
->willReturn($customer);
62-
$this->addressRepository->expects($this->once())
63-
->method('getById')
6450
->willThrowException(new NoSuchEntityException());
6551

6652
$this->assertEquals(['code' => null], $this->buyerCountry->getSectionData());
@@ -90,22 +76,28 @@ public function testGetSectionDataNoAddress(): void
9076
*/
9177
public function testGetSectionDataShippingAddress(): void
9278
{
79+
$addressId = 1;
80+
$countryId = 'US';
81+
$address = $this->createMock(AddressInterface::class);
82+
$address->expects($this->once())
83+
->method('getCountryId')
84+
->willReturn($countryId);
85+
$address->expects($this->once())
86+
->method('getId')
87+
->willReturn($addressId);
9388
$customer = $this->createMock(CustomerInterface::class);
9489
$customer->expects($this->once())
9590
->method('getDefaultBilling')
9691
->willReturn(null);
9792
$customer->expects($this->once())
9893
->method('getDefaultShipping')
99-
->willReturn(1);
94+
->willReturn($addressId);
95+
$customer->expects($this->once())->method('getAddresses')
96+
->willReturn([$address]);
10097
$this->currentCustomer->expects($this->once())
10198
->method('getCustomer')
10299
->willReturn($customer);
103-
$address = $this->createMock(AddressInterface::class);
104-
$address->expects($this->once())
105-
->method('getCountryId')
106-
->willReturn('US');
107-
$this->addressRepository->expects($this->once())->method('getById')->willReturn($address);
108100

109-
$this->assertEquals(['code' => 'US'], $this->buyerCountry->getSectionData());
101+
$this->assertEquals(['code' => $countryId], $this->buyerCountry->getSectionData());
110102
}
111103
}

0 commit comments

Comments
 (0)