Skip to content

Commit 6acfd6a

Browse files
Merge pull request magento#9310 from magento-gl/comprs_v2
[Bluetooth] Community Pull Requests delivery Oct-v2
2 parents 7b336d0 + f409c93 commit 6acfd6a

File tree

12 files changed

+113
-48
lines changed

12 files changed

+113
-48
lines changed

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22
/**
3-
*
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
65
*/
76

87
namespace Magento\Catalog\Model;
@@ -149,7 +148,7 @@ public function save(CategoryInterface $category)
149148
*/
150149
public function get($categoryId, $storeId = null)
151150
{
152-
$cacheKey = $storeId ?? 'all';
151+
$cacheKey = $storeId ?? $this->storeManager->getStore()->getId();
153152
if (!isset($this->instances[$categoryId][$cacheKey])) {
154153
/** @var Category $category */
155154
$category = $this->categoryFactory->create();
@@ -231,7 +230,7 @@ protected function validateCategory(Category $category)
231230
* Lazy loader for the converter.
232231
*
233232
* @return ExtensibleDataObjectConverter
234-
*
233+
* phpcs:disable Magento2.Annotation.MethodAnnotationStructure
235234
* @deprecated 101.0.0
236235
* @see we don't recommend this approach anymore
237236
*/

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 3 additions & 9 deletions
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 2011 Adobe
4+
* All Rights Reserved.
55
*/
66

77
/**
@@ -37,8 +37,6 @@ class Category extends AbstractResource implements ResetAfterRequestInterface
3737
protected $_tree;
3838

3939
/**
40-
* Catalog products table name
41-
*
4240
* @var string
4341
*/
4442
protected $_categoryProductTable;
@@ -49,15 +47,11 @@ class Category extends AbstractResource implements ResetAfterRequestInterface
4947
private $entitiesWhereAttributesIs;
5048

5149
/**
52-
* Id of 'is_active' category attribute
53-
*
5450
* @var int
5551
*/
5652
protected $_isActiveAttributeId = null;
5753

5854
/**
59-
* Id of store
60-
*
6155
* @var int
6256
*/
6357
protected $_storeId = null;
@@ -455,7 +449,7 @@ protected function _saveCategoryProducts($category)
455449
'position' => (int)$position,
456450
];
457451
}
458-
$connection->insertMultiple($this->getCategoryProductTable(), $data);
452+
$connection->insertOnDuplicate($this->getCategoryProductTable(), $data, ['position']);
459453
}
460454

461455
/**

app/code/Magento/Config/Model/Config/Backend/Baseurl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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
namespace Magento\Config\Model\Config\Backend;
77

8-
use Magento\Framework\Validator\Url as UrlValidator;
98
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Validator\Url as UrlValidator;
1010

1111
/**
1212
* @api
@@ -56,7 +56,7 @@ public function __construct(
5656
*/
5757
public function beforeSave()
5858
{
59-
$value = $this->getValue();
59+
$value = strtolower($this->getValue());
6060
try {
6161
if (!$this->_validateUnsecure($value) && !$this->_validateSecure($value)) {
6262
$this->_validateFullyQualifiedUrl($value);
@@ -68,6 +68,7 @@ public function beforeSave()
6868
$error = new \Magento\Framework\Exception\LocalizedException($msg, $e);
6969
throw $error;
7070
}
71+
$this->setValue($value);
7172
}
7273

7374
/**
@@ -232,6 +233,7 @@ public function afterSave()
232233
* Get URL Validator
233234
*
234235
* @deprecated 100.1.12
236+
* @see Nothing
235237
* @return UrlValidator
236238
*/
237239
private function getUrlValidator()

app/code/Magento/Config/Test/Unit/Model/Config/Backend/BaseurlTest.php

Lines changed: 57 additions & 2 deletions
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

@@ -17,9 +17,17 @@
1717
use Magento\Framework\Registry;
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1919
use Magento\Framework\View\Asset\MergeService;
20+
use Magento\Framework\Validator\Url as UrlValidator;
21+
use Magento\Framework\App\ObjectManager as AppObjectManager;
22+
use Magento\Framework\ObjectManagerInterface;
2023
use Magento\Store\Model\Store;
2124
use PHPUnit\Framework\TestCase;
2225

26+
/**
27+
* Test Class BaseurlTest
28+
*
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
*/
2331
class BaseurlTest extends TestCase
2432
{
2533
public function testSaveMergedJsCssMustBeCleaned()
@@ -61,4 +69,51 @@ public function testSaveMergedJsCssMustBeCleaned()
6169
$model->setValue('http://example.com/')->setPath(Store::XML_PATH_UNSECURE_BASE_URL);
6270
$model->afterSave();
6371
}
72+
73+
/**
74+
* Test beforeSave method to ensure URL is converted to lower case.
75+
*
76+
* @dataProvider beforeSaveDataProvider
77+
* @param string $value
78+
* @param string $expectedValue
79+
* @return void
80+
*/
81+
public function testBeforeSaveConvertLowerCase(string $value, string $expectedValue): void
82+
{
83+
$model = (new ObjectManager($this))->getObject(Baseurl::class);
84+
85+
$urlValidatorMock = $this->getMockBuilder(UrlValidator::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
89+
$objectManagerInterface = $this->createMock(ObjectManagerInterface::class);
90+
$objectManagerInterface->expects($this->exactly(1))
91+
->method('get')
92+
->with(UrlValidator::class)
93+
->willReturn($urlValidatorMock);
94+
AppObjectManager::setInstance($objectManagerInterface);
95+
96+
$urlValidatorMock->expects($this->once())
97+
->method('isValid')
98+
->with($expectedValue, ['http', 'https'])
99+
->willReturn(true);
100+
101+
$model->setValue($value);
102+
$model->beforeSave();
103+
$this->assertEquals($expectedValue, $model->getValue());
104+
}
105+
106+
/**
107+
* Data provider for testBeforeSaveConvertLowerCase.
108+
*
109+
* @return array
110+
*/
111+
public static function beforeSaveDataProvider(): array
112+
{
113+
return [
114+
['https://Example1.com/', 'https://example1.com/'],
115+
['https://EXAMPLE2.COM/', 'https://example2.com/'],
116+
['HTtpS://ExamPLe3.COM/', 'https://example3.com/'],
117+
];
118+
}
64119
}

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ sub vcl_recv {
7777
std.collect(req.http.Cookie);
7878

7979
# Remove all marketing get parameters to minimize the cache objects
80-
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
81-
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
80+
if (req.url ~ "(\?|&)(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
81+
set req.url = regsuball(req.url, "(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
8282
set req.url = regsub(req.url, "[?|&]+$", "");
8383
}
8484

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ sub vcl_recv {
7878
std.collect(req.http.Cookie);
7979

8080
# Remove all marketing get parameters to minimize the cache objects
81-
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
82-
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
81+
if (req.url ~ "(\?|&)(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
82+
set req.url = regsuball(req.url, "(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
8383
set req.url = regsub(req.url, "[?|&]+$", "");
8484
}
8585

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ sub vcl_recv {
8282
std.collect(req.http.Cookie);
8383

8484
# Remove all marketing get parameters to minimize the cache objects
85-
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
86-
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
85+
if (req.url ~ "(\?|&)(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
86+
set req.url = regsuball(req.url, "(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
8787
set req.url = regsub(req.url, "[?|&]+$", "");
8888
}
8989

app/code/Magento/PageCache/etc/varnish7.vcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ sub vcl_recv {
8282
std.collect(req.http.Cookie);
8383

8484
# Remove all marketing get parameters to minimize the cache objects
85-
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
86-
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
85+
if (req.url ~ "(\?|&)(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
86+
set req.url = regsuball(req.url, "(gad_source|gbraid|wbraid|_gl|dclid|gclsrc|srsltid|msclkid|gclid|cx|_kx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
8787
set req.url = regsub(req.url, "[?|&]+$", "");
8888
}
8989

app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Ui\Controller\Adminhtml\Bookmark;
79

810
use Magento\Authorization\Model\UserContextInterface;
@@ -246,17 +248,32 @@ private function updateCurrentBookmarkConfig(array $data): void
246248
$bookmarkConfig = $bookmark->getConfig();
247249
$existingConfig = $bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] ?? null;
248250
$currentConfig = $data[self::CURRENT_IDENTIFIER] ?? null;
249-
if ($existingConfig && $currentConfig) {
250-
if ($existingConfig['filters'] === $currentConfig['filters']
251-
&& $existingConfig['positions'] !== $currentConfig['positions']
252-
) {
253-
$bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] = $data[self::CURRENT_IDENTIFIER];
254-
$bookmark->setConfig($this->serializer->serialize($bookmarkConfig));
255-
$this->bookmarkRepository->save($bookmark);
256-
}
251+
if ($existingConfig && $currentConfig && $this->isPositionChanged($existingConfig, $currentConfig)) {
252+
$bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] = $data[self::CURRENT_IDENTIFIER];
253+
$bookmark->setConfig($this->serializer->serialize($bookmarkConfig));
254+
$this->bookmarkRepository->save($bookmark);
257255
}
258256
break;
259257
}
260258
}
261259
}
260+
261+
/**
262+
* Check if the positions for identical filters has changed
263+
*
264+
* @param array $existingConfig The existing configuration
265+
* @param array $currentConfig The current configuration
266+
* @return bool True if positions have changed, false otherwise
267+
*/
268+
private function isPositionChanged(array $existingConfig, array $currentConfig): bool
269+
{
270+
foreach (['filters', 'positions'] as $key) {
271+
if (!array_key_exists($key, $existingConfig) || !array_key_exists($key, $currentConfig)) {
272+
return false;
273+
}
274+
}
275+
276+
return $existingConfig['filters'] === $currentConfig['filters']
277+
&& $existingConfig['positions'] !== $currentConfig['positions'];
278+
}
262279
}

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/Save/UpdateCategoryTest.php

Lines changed: 3 additions & 4 deletions
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 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -48,10 +48,9 @@ protected function setUp(): void
4848
public function testUpdateCategoryForDefaultStoreView(array $postData): void
4949
{
5050
$storeId = (int)$this->storeManager->getStore('default')->getId();
51-
$postData = array_merge($postData, ['store_id' => $storeId]);
5251
$responseData = $this->performSaveCategoryRequest($postData);
5352
$this->assertRequestIsSuccessfullyPerformed($responseData);
54-
$category = $this->categoryRepository->get($postData['entity_id'], $postData['store_id']);
53+
$category = $this->categoryRepository->get($postData['entity_id'], $storeId);
5554
unset($postData['use_default']);
5655
unset($postData['use_config']);
5756
foreach ($postData as $key => $value) {

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 3 additions & 4 deletions
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 2012 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -153,7 +153,6 @@ public function testDefaultValueForCategoryUrlPath(): void
153153
$categoryId = 3;
154154
$category = $this->categoryRepository->get($categoryId);
155155
$newUrlPath = 'test_url_path';
156-
$defaultUrlPath = $category->getData('url_path');
157156

158157
// update url_path and check it
159158
$category->setStoreId(1);
@@ -178,7 +177,7 @@ public function testDefaultValueForCategoryUrlPath(): void
178177
MessageInterface::TYPE_SUCCESS
179178
);
180179
$category = $this->categoryRepository->get($categoryId);
181-
$this->assertEquals($defaultUrlPath, $category->getData('url_key'));
180+
$this->assertEquals($newUrlPath, $category->getData('url_key'));
182181
}
183182

184183
/**

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testChildrenUrlPathContainsParentCustomScopeUrlKey()
105105
[
106106
'parent_id' => $category1->getId(),
107107
'name' => 'Category 2',
108-
'url_key' => null,
108+
'url_key' => 'category-2',
109109
'is_active' => true
110110
]
111111
);
@@ -114,7 +114,7 @@ public function testChildrenUrlPathContainsParentCustomScopeUrlKey()
114114
$this->storeManager->setCurrentStore($secondStore);
115115

116116
$category2 = $this->categoryRepository->get($category2->getId());
117-
$category2->setUrlKey(null);
117+
$category2->setUrlKey('category-2');
118118
$this->categoryRepository->save($category2);
119119

120120
$this->storeManager->setCurrentStore(StoreModel::DEFAULT_STORE_ID);

0 commit comments

Comments
 (0)