Skip to content

Commit ff1149c

Browse files
Merge remote-tracking branch 'origin' into AC-11421-New
2 parents 3304a03 + 6a18520 commit ff1149c

File tree

17 files changed

+869
-58
lines changed

17 files changed

+869
-58
lines changed

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,19 @@ define([
7171
* @param {Number|String} index - element index
7272
*/
7373
removeBundleItemsFromOption: function (index) {
74-
var bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName),
75-
bundleSelectionsLength = (bundleSelections.elems() || []).length,
76-
i;
74+
let bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName);
7775

78-
if (bundleSelectionsLength) {
79-
for (i = 0; i < bundleSelectionsLength; i++) {
80-
bundleSelections.elems()[0].destroy();
81-
}
82-
}
76+
bundleSelections.destroyChildren();
8377
},
8478

8579
/**
8680
* {@inheritdoc}
8781
*/
8882
processingAddChild: function (ctx, index, prop) {
8983
var recordIds = _.map(this.recordData(), function (rec) {
90-
return parseInt(rec['record_id'], 10);
91-
}),
92-
maxRecordId = _.max(recordIds);
84+
return parseInt(rec['record_id'], 10);
85+
}),
86+
maxRecordId = _.max(recordIds);
9387

9488
prop = maxRecordId > -1 ? maxRecordId + 1 : prop;
9589
this._super(ctx, index, prop);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* ************************************************************************
8+
*/
9+
declare(strict_types=1);
10+
11+
namespace Magento\Paypal\CustomerData;
12+
13+
use Magento\Customer\CustomerData\SectionSourceInterface;
14+
use Magento\Customer\Helper\Session\CurrentCustomer;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
17+
class BuyerCountry implements SectionSourceInterface
18+
{
19+
/**
20+
* @param CurrentCustomer $currentCustomer
21+
*/
22+
public function __construct(private readonly CurrentCustomer $currentCustomer)
23+
{
24+
}
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function getSectionData()
30+
{
31+
$country = null;
32+
try {
33+
$customer = $this->currentCustomer->getCustomer();
34+
$addressId = $customer->getDefaultBilling() ?
35+
$customer->getDefaultBilling() :
36+
$customer->getDefaultShipping();
37+
38+
if ($addressId) {
39+
foreach ($customer->getAddresses() as $address) {
40+
if ($address->getId() == $addressId) {
41+
$country = $address->getCountryId();
42+
break;
43+
}
44+
}
45+
}
46+
} catch (NoSuchEntityException $e) {
47+
return [
48+
'code' => null
49+
];
50+
}
51+
52+
return [
53+
'code' => $country
54+
];
55+
}
56+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* ************************************************************************
8+
*/
9+
declare(strict_types=1);
10+
11+
namespace Magento\Paypal\Test\Unit\CustomerData;
12+
13+
use Magento\Customer\Api\Data\AddressInterface;
14+
use Magento\Customer\Api\Data\CustomerInterface;
15+
use Magento\Customer\Helper\Session\CurrentCustomer;
16+
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Paypal\CustomerData\BuyerCountry;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class BuyerCountryTest extends TestCase
22+
{
23+
/**
24+
* @var CurrentCustomer|MockObject
25+
*/
26+
private CurrentCustomer $currentCustomer;
27+
28+
/**
29+
* @var BuyerCountry
30+
*/
31+
private BuyerCountry $buyerCountry;
32+
33+
/**
34+
* @return void
35+
*/
36+
protected function setUp(): void
37+
{
38+
$this->currentCustomer = $this->createMock(CurrentCustomer::class);
39+
40+
$this->buyerCountry = new BuyerCountry($this->currentCustomer);
41+
}
42+
43+
/**
44+
* @return void
45+
*/
46+
public function testGetSectionDataException(): void
47+
{
48+
$this->currentCustomer->expects($this->once())
49+
->method('getCustomer')
50+
->willThrowException(new NoSuchEntityException());
51+
52+
$this->assertEquals(['code' => null], $this->buyerCountry->getSectionData());
53+
}
54+
55+
/**
56+
* @return void
57+
*/
58+
public function testGetSectionDataNoAddress(): void
59+
{
60+
$customer = $this->createMock(CustomerInterface::class);
61+
$customer->expects($this->once())
62+
->method('getDefaultBilling')
63+
->willReturn(null);
64+
$customer->expects($this->once())
65+
->method('getDefaultShipping')
66+
->willReturn(null);
67+
$this->currentCustomer->expects($this->once())
68+
->method('getCustomer')
69+
->willReturn($customer);
70+
71+
$this->assertEquals(['code' => null], $this->buyerCountry->getSectionData());
72+
}
73+
74+
/**
75+
* @return void
76+
*/
77+
public function testGetSectionDataShippingAddress(): void
78+
{
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);
88+
$customer = $this->createMock(CustomerInterface::class);
89+
$customer->expects($this->once())
90+
->method('getDefaultBilling')
91+
->willReturn(null);
92+
$customer->expects($this->once())
93+
->method('getDefaultShipping')
94+
->willReturn($addressId);
95+
$customer->expects($this->once())->method('getAddresses')
96+
->willReturn([$address]);
97+
$this->currentCustomer->expects($this->once())
98+
->method('getCustomer')
99+
->willReturn($customer);
100+
101+
$this->assertEquals(['code' => $countryId], $this->buyerCountry->getSectionData());
102+
}
103+
}

app/code/Magento/Paypal/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<arguments>
120120
<argument name="sectionSourceMap" xsi:type="array">
121121
<item name="paypal-billing-agreement" xsi:type="string">Magento\Paypal\CustomerData\BillingAgreement</item>
122+
<item name="paypal-buyer-country" xsi:type="string">Magento\Paypal\CustomerData\BuyerCountry</item>
122123
</argument>
123124
</arguments>
124125
</type>

app/code/Magento/Paypal/view/frontend/web/js/view/paylater.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ define([
99
'uiElement',
1010
'uiLayout',
1111
'Magento_Paypal/js/in-context/paypal-sdk',
12+
'Magento_Customer/js/customer-data',
1213
'domReady!'
1314
], function (
1415
$,
1516
ko,
1617
Component,
1718
layout,
18-
paypalSdk
19+
paypalSdk,
20+
customerData
1921
) {
2022
'use strict';
2123

@@ -37,13 +39,17 @@ define([
3739
},
3840
paypal: null,
3941
amount: null,
42+
buyerCountry: null,
4043

4144
/**
4245
* Initialize
4346
*
4447
* @returns {*}
4548
*/
4649
initialize: function () {
50+
let buyerCountry = customerData.get('paypal-buyer-country');
51+
52+
this.buyerCountry = buyerCountry().code;
4753
this._super()
4854
.observe(['amount']);
4955

app/code/Magento/Paypal/view/frontend/web/template/paylater.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<div data-pp-message data-bind="attr: {
8-
'class': getAttribute('class'),
9-
'data-pp-amount': amount,
10-
'data-pp-placement': getAttribute('data-pp-placement'),
11-
'data-pp-style-layout': getAttribute('data-pp-style-layout'),
12-
'data-pp-style-logo-type': getAttribute('data-pp-style-logo-type'),
13-
'data-pp-style-logo-position': getAttribute('data-pp-style-logo-position'),
14-
'data-pp-style-text-color': getAttribute('data-pp-style-text-color'),
15-
'data-pp-style-text-size': getAttribute('data-pp-style-text-size'),
16-
'data-pp-style-color': getAttribute('data-pp-style-color'),
17-
'data-pp-style-ratio': getAttribute('data-pp-style-ratio'),
18-
}" ></div>
7+
<div data-bind="if: buyerCountry">
8+
<div data-pp-message data-bind="attr: {
9+
'class': getAttribute('class'),
10+
'data-pp-amount': amount,
11+
'data-pp-placement': getAttribute('data-pp-placement'),
12+
'data-pp-style-layout': getAttribute('data-pp-style-layout'),
13+
'data-pp-style-logo-type': getAttribute('data-pp-style-logo-type'),
14+
'data-pp-style-logo-position': getAttribute('data-pp-style-logo-position'),
15+
'data-pp-style-text-color': getAttribute('data-pp-style-text-color'),
16+
'data-pp-style-text-size': getAttribute('data-pp-style-text-size'),
17+
'data-pp-style-color': getAttribute('data-pp-style-color'),
18+
'data-pp-style-ratio': getAttribute('data-pp-style-ratio'),
19+
'data-pp-buyercountry': buyerCountry
20+
}" ></div>
21+
</div>
1922

0 commit comments

Comments
 (0)