Skip to content

Commit 55a9430

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into AC-13818
2 parents c0ecda4 + 344fce2 commit 55a9430

26 files changed

+878
-61
lines changed

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Bundle\Pricing\Adjustment;
@@ -173,12 +173,9 @@ private function addMiniMaxPriceList(Product $bundleProduct, $selectionsCollecti
173173
*/
174174
private function addMaximumMultiSelectionPriceList(Product $bundleProduct, $selectionsCollection, $useRegularPrice)
175175
{
176-
$websiteId = null;
177-
if (!$this->catalogData->isPriceGlobal()) {
178-
$websiteId = (int)$this->storeManager->getStore()->getWebsiteId();
179-
if ($websiteId === 0) {
180-
$websiteId = $this->websiteRepository->getDefault()->getId();
181-
}
176+
$websiteId = (int)$this->storeManager->getStore()->getWebsiteId();
177+
if ($websiteId === 0) {
178+
$websiteId = $this->websiteRepository->getDefault()->getId();
182179
}
183180
$selectionsCollection->addPriceData(null, $websiteId);
184181

app/code/Magento/Bundle/Test/Unit/Pricing/Adjustment/DefaultSelectionPriceListProviderTest.php

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -189,7 +189,10 @@ public function testGetPriceList(): void
189189
$this->model->getPriceList($this->product, false, false);
190190
}
191191

192-
public function testGetPriceListForFixedPriceType(): void
192+
/**
193+
* @dataProvider dataProvider
194+
*/
195+
public function testGetPriceListForFixedPriceType($websiteId): void
193196
{
194197
$optionId = 1;
195198

@@ -218,13 +221,19 @@ public function testGetPriceListForFixedPriceType(): void
218221
->willReturn($this->store);
219222
$this->store->expects($this->once())
220223
->method('getWebsiteId')
221-
->willReturn(0);
222-
$this->websiteRepository->expects($this->once())
223-
->method('getDefault')
224-
->willReturn($this->website);
225-
$this->website->expects($this->once())
226-
->method('getId')
227-
->willReturn(1);
224+
->willReturn($websiteId);
225+
226+
if ($websiteId) {
227+
$this->websiteRepository->expects($this->never())
228+
->method('getDefault');
229+
} else {
230+
$this->websiteRepository->expects($this->once())
231+
->method('getDefault')
232+
->willReturn($this->website);
233+
$this->website->expects($this->once())
234+
->method('getId')
235+
->willReturn(1);
236+
}
228237
$this->selectionCollection->expects($this->once())
229238
->method('getIterator')
230239
->willReturn(new \ArrayIterator([]));
@@ -271,4 +280,12 @@ public function testGetPriceListWithSearchMin(): void
271280

272281
$this->model->getPriceList($this->product, true, false);
273282
}
283+
284+
public static function dataProvider()
285+
{
286+
return [
287+
'website provided' => [1],
288+
'website not provided' => [0]
289+
];
290+
}
274291
}

app/code/Magento/Directory/Test/Unit/Model/Country/Postcode/ValidatorTest.php

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -31,17 +31,25 @@ protected function setUp(): void
3131
'US' => [
3232
'pattern_1' => ['pattern' => '^[0-9]{5}\-[0-9]{4}$'],
3333
'pattern_2' => ['pattern' => '^[0-9]{5}$']
34+
],
35+
'NL' => [
36+
'pattern_1' => ['pattern' => '^[1-9][0-9]{3}\s?[a-zA-Z]{2}$'],
37+
'pattern_2' => ['pattern' => '^[1-9][0-9]{3}$']
3438
]
3539
];
3640
$this->postcodesConfigMock->expects($this->once())->method('getPostCodes')->willReturn($postCodes);
3741
$this->model = new Validator($this->postcodesConfigMock);
3842
}
3943

40-
public function testValidatePositive()
44+
/**
45+
* @param string $postCode
46+
* @param string $countryId
47+
* @return void
48+
* @dataProvider getCountryPostcodes
49+
*/
50+
public function testValidatePositive(string $postCode, string $countryId): void
4151
{
42-
$postcode = '12345-6789';
43-
$countryId = 'US';
44-
$this->assertTrue($this->model->validate($postcode, $countryId));
52+
$this->assertTrue($this->model->validate($postCode, $countryId));
4553
}
4654

4755
public function testValidateNegative()
@@ -59,4 +67,25 @@ public function testValidateThrowExceptionIfCountryDoesNotExist()
5967
$countryId = 'QQ';
6068
$this->assertFalse($this->model->validate($postcode, $countryId));
6169
}
70+
71+
/**
72+
* @return \string[][]
73+
*/
74+
public static function getCountryPostcodes(): array
75+
{
76+
return [
77+
[
78+
'postCode' => '12345-6789',
79+
'countryId' => 'US'
80+
],
81+
[
82+
'postCode' => '1234',
83+
'countryId' => 'NL'
84+
],
85+
[
86+
'postCode' => '1234AB',
87+
'countryId' => 'NL'
88+
]
89+
];
90+
}
6291
}

app/code/Magento/Directory/etc/zip_codes.xml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0"?>
22
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
6-
*/
3+
/**
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Directory:etc/zip_codes.xsd">
99
<zip countryCode="AD">
@@ -569,6 +569,7 @@
569569
<zip countryCode="NL">
570570
<codes>
571571
<code id="pattern_1" active="true" example="1234 AB/1234AB">^[1-9][0-9]{3}\s?[a-zA-Z]{2}$</code>
572+
<code id="pattern_2" active="true" example="1234">^[1-9][0-9]{3}$</code>
572573
</codes>
573574
</zip>
574575
<zip countryCode="NO">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe.
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Block\Header;
9+
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Serialize\Serializer\JsonHexTag;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
use Magento\Framework\View\Element\Template;
14+
use Magento\Framework\View\Element\Template\Context;
15+
use Magento\Persistent\Model\CheckoutConfigProvider;
16+
17+
class RememberMeInit extends Template
18+
{
19+
/**
20+
* @param Context $context
21+
* @param array $data
22+
* @param SerializerInterface|null $serializer
23+
* @param CheckoutConfigProvider|null $checkoutConfigProvider
24+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
25+
*/
26+
public function __construct(
27+
Context $context,
28+
array $data = [],
29+
private ?SerializerInterface $serializer = null,
30+
private ?CheckoutConfigProvider $checkoutConfigProvider = null
31+
) {
32+
parent::__construct($context, $data);
33+
$this->serializer = $serializer ?: ObjectManager::getInstance()
34+
->get(JsonHexTag::class);
35+
$this->checkoutConfigProvider = $checkoutConfigProvider ?: ObjectManager::getInstance()
36+
->get(CheckoutConfigProvider::class);
37+
}
38+
39+
/**
40+
* Retrieve serialized config.
41+
*
42+
* @return string|bool
43+
*/
44+
private function getSerializedCheckoutConfig(): string|bool
45+
{
46+
return $this->serializer->serialize($this->checkoutConfigProvider->getConfig());
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function toHtml()
53+
{
54+
$html = parent::toHtml();
55+
$serializedConfig = $this->getSerializedCheckoutConfig();
56+
$jsString = '<script type="text/x-magento-init">{"*":
57+
{"Magento_Persistent/js/remember-me-config": {
58+
"config": ' . $serializedConfig . '
59+
}}}</script>';
60+
61+
$html .= $jsString;
62+
return $html;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Observer;
9+
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\Event\ObserverInterface;
13+
use Magento\Persistent\Helper\Data;
14+
15+
/**
16+
* Observer to add layout handle for persistent remember me init
17+
*
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
19+
*/
20+
class AddPersistentRememberMeInitObserver implements ObserverInterface
21+
{
22+
23+
/**
24+
* @param Data $persistentData
25+
* @param Session $customerSession
26+
*/
27+
public function __construct(
28+
private Data $persistentData,
29+
private Session $customerSession,
30+
) {
31+
}
32+
33+
/**
34+
* Apply persistent remember me init config to layout on certain conditions
35+
*
36+
* @param Observer $observer
37+
* @return $this
38+
*/
39+
public function execute(Observer $observer): static
40+
{
41+
if ($this->customerSession->isLoggedIn()
42+
|| !$this->persistentData->isEnabled()
43+
|| !$this->persistentData->isRememberMeEnabled()
44+
) {
45+
return $this;
46+
}
47+
48+
/** @var \Magento\Framework\View\Layout $layout */
49+
$layout = $observer->getEvent()->getData('layout');
50+
$layout->getUpdate()->addHandle('remember_me');
51+
return $this;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Plugin;
9+
10+
use Magento\Framework\View\Layout;
11+
use Magento\Persistent\Block\Header\RememberMeInit;
12+
use Magento\Persistent\Helper\Data;
13+
use Magento\Customer\Model\Session;
14+
15+
/**
16+
* Plugin to add layout handle and block for persistent remember me init
17+
*
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
19+
*/
20+
class AddPersistentRememberMeInitPlugin
21+
{
22+
/**
23+
* @param Data $persistentData
24+
* @param Session $customerSession
25+
*/
26+
public function __construct(
27+
private readonly Data $persistentData,
28+
private readonly Session $customerSession
29+
) {
30+
}
31+
32+
/**
33+
* Add the RememberMeInit block to the layout.
34+
*
35+
* @param Layout $subject
36+
* @param callable $proceed
37+
* @return void
38+
*/
39+
public function aroundGenerateElements(Layout $subject, callable $proceed)
40+
{
41+
$proceed();
42+
43+
if (!$this->customerSession->isLoggedIn()
44+
&& $this->persistentData->isEnabled()
45+
&& $this->persistentData->isRememberMeEnabled()
46+
) {
47+
if ($subject->getBlock('head.additional') &&
48+
!$subject->getBlock('persistent_initial_configs')) {
49+
$subject->addBlock(
50+
RememberMeInit::class,
51+
'persistent_initial_configs'
52+
);
53+
$subject->addOutputElement('persistent_initial_configs');
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)