Skip to content

Commit c9c60a4

Browse files
Merge branch '2.4-develop' of github.com:magento-commerce/magento2ce into ACPT-757&ACPT-773&ACPT-747&ACPT-748&ACPT-675&ACPT-671&ACPT-746
2 parents 9413762 + 78dd065 commit c9c60a4

File tree

11 files changed

+194
-331
lines changed

11 files changed

+194
-331
lines changed

app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
* @param ProductRepositoryInterface $subject
5050
* @param ProductInterface $product
5151
* @param bool $saveOptions
52-
* @return array
52+
* @return void
5353
* @throws InputException
5454
* @throws NoSuchEntityException
5555
*
@@ -59,34 +59,23 @@ public function beforeSave(
5959
ProductRepositoryInterface $subject,
6060
ProductInterface $product,
6161
$saveOptions = false
62-
): array {
63-
$result[] = $product;
64-
if ($product->getTypeId() !== Configurable::TYPE_CODE) {
65-
return $result;
66-
}
67-
62+
): void {
6863
$extensionAttributes = $product->getExtensionAttributes();
69-
if ($extensionAttributes === null) {
70-
return $result;
71-
}
72-
73-
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
74-
$configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
64+
if ($extensionAttributes !== null && $product->getTypeId() === Configurable::TYPE_CODE) {
65+
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
66+
$configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
7567

76-
if (empty($configurableLinks) && empty($configurableOptions)) {
77-
return $result;
78-
}
79-
80-
$attributeCodes = [];
81-
/** @var OptionInterface $configurableOption */
82-
foreach ($configurableOptions as $configurableOption) {
83-
$eavAttribute = $this->productAttributeRepository->get($configurableOption->getAttributeId());
84-
$attributeCode = $eavAttribute->getAttributeCode();
85-
$attributeCodes[] = $attributeCode;
68+
if (!empty($configurableLinks) || !empty($configurableOptions)) {
69+
$attributeCodes = [];
70+
/** @var OptionInterface $configurableOption */
71+
foreach ($configurableOptions as $configurableOption) {
72+
$eavAttribute = $this->productAttributeRepository->get($configurableOption->getAttributeId());
73+
$attributeCode = $eavAttribute->getAttributeCode();
74+
$attributeCodes[] = $attributeCode;
75+
}
76+
$this->validateProductLinks($attributeCodes, $configurableLinks);
77+
}
8678
}
87-
$this->validateProductLinks($attributeCodes, $configurableLinks);
88-
89-
return $result;
9079
}
9180

9281
/**

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/ProductRepositorySaveTest.php

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,13 @@ protected function setUp(): void
113113
*/
114114
public function testBeforeSaveWhenProductIsSimple(): void
115115
{
116-
$this->product->expects(static::once())
116+
$this->product->expects(static::atMost(1))
117117
->method('getTypeId')
118118
->willReturn('simple');
119-
$this->product->expects(static::never())
119+
$this->product->expects(static::once())
120120
->method('getExtensionAttributes');
121121

122-
$this->assertEquals(
123-
$this->product,
124-
$this->plugin->beforeSave($this->productRepository, $this->product)[0]
125-
);
122+
$this->assertNull($this->plugin->beforeSave($this->productRepository, $this->product));
126123
}
127124

128125
/**
@@ -150,52 +147,7 @@ public function testBeforeSaveWithoutOptions(): void
150147
$this->productAttributeRepository->expects(static::never())
151148
->method('get');
152149

153-
$this->assertEquals(
154-
$this->product,
155-
$this->plugin->beforeSave($this->productRepository, $this->product)[0]
156-
);
157-
}
158-
159-
/**
160-
* Test saving a configurable product with same set of attribute values
161-
*
162-
* @return void
163-
*/
164-
public function testBeforeSaveWithLinks(): void
165-
{
166-
$this->expectException(InputException::class);
167-
$this->expectExceptionMessage('Products "5" and "4" have the same set of attribute values.');
168-
$links = [4, 5];
169-
$this->product->expects(static::once())
170-
->method('getTypeId')
171-
->willReturn(Configurable::TYPE_CODE);
172-
173-
$this->product->expects(static::once())
174-
->method('getExtensionAttributes')
175-
->willReturn($this->extensionAttributes);
176-
$this->extensionAttributes->expects(static::once())
177-
->method('getConfigurableProductOptions')
178-
->willReturn(null);
179-
$this->extensionAttributes->expects(static::once())
180-
->method('getConfigurableProductLinks')
181-
->willReturn($links);
182-
183-
$this->productAttributeRepository->expects(static::never())
184-
->method('get');
185-
186-
$product = $this->getMockBuilder(Product::class)
187-
->disableOriginalConstructor()
188-
->setMethods(['getData'])
189-
->getMock();
190-
191-
$this->productRepository->expects(static::exactly(2))
192-
->method('getById')
193-
->willReturn($product);
194-
195-
$product->expects(static::never())
196-
->method('getData');
197-
198-
$this->plugin->beforeSave($this->productRepository, $this->product);
150+
$this->assertNull($this->plugin->beforeSave($this->productRepository, $this->product));
199151
}
200152

201153
/**
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Directory\Setup\Patch\Data;
9+
10+
use Magento\Directory\Setup\DataInstaller;
11+
use Magento\Directory\Setup\DataInstallerFactory;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Framework\Setup\Patch\DataPatchInterface;
14+
15+
/**
16+
* Add Czech Republic States
17+
*/
18+
class AddDataForCzechia implements DataPatchInterface
19+
{
20+
/**
21+
* @var ModuleDataSetupInterface
22+
*/
23+
private $moduleDataSetup;
24+
25+
/**
26+
* @var DataInstallerFactory
27+
*/
28+
private $dataInstallerFactory;
29+
30+
/**
31+
* @param ModuleDataSetupInterface $moduleDataSetup
32+
* @param DataInstallerFactory $dataInstallerFactory
33+
*/
34+
public function __construct(
35+
ModuleDataSetupInterface $moduleDataSetup,
36+
DataInstallerFactory $dataInstallerFactory
37+
) {
38+
$this->moduleDataSetup = $moduleDataSetup;
39+
$this->dataInstallerFactory = $dataInstallerFactory;
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function apply()
46+
{
47+
/** @var DataInstaller $dataInstaller */
48+
$dataInstaller = $this->dataInstallerFactory->create();
49+
$dataInstaller->addCountryRegions(
50+
$this->moduleDataSetup->getConnection(),
51+
$this->getDataForCzechia()
52+
);
53+
54+
return $this;
55+
}
56+
57+
/**
58+
* Czechia states data.
59+
*
60+
* @return array
61+
*/
62+
private function getDataForCzechia()
63+
{
64+
return [
65+
['CZ', 'CZ-10', 'Praha, Hlavní město'],
66+
['CZ', 'CZ-20', 'Středočeský kraj'],
67+
['CZ', 'CZ-31', 'Jihočeský kraj'],
68+
['CZ', 'CZ-32', 'Plzeňský kraj'],
69+
['CZ', 'CZ-41', 'Karlovarský kraj'],
70+
['CZ', 'CZ-42', 'Ústecký kraj'],
71+
['CZ', 'CZ-51', 'Liberecký kraj'],
72+
['CZ', 'CZ-52', 'Královéhradecký kraj'],
73+
['CZ', 'CZ-53', 'Pardubický kraj'],
74+
['CZ', 'CZ-63', 'Kraj Vysočina'],
75+
['CZ', 'CZ-64', 'Jihomoravský kraj'],
76+
['CZ', 'CZ-71', 'Olomoucký kraj'],
77+
['CZ', 'CZ-72', 'Zlínský kraj'],
78+
['CZ', 'CZ-80', 'Moravskoslezský kraj'],
79+
];
80+
}
81+
82+
/**
83+
* @inheritdoc
84+
*/
85+
public static function getDependencies()
86+
{
87+
return [
88+
InitializeDirectoryData::class,
89+
];
90+
}
91+
92+
/**
93+
* @inheritdoc
94+
*/
95+
public function getAliases()
96+
{
97+
return [];
98+
}
99+
}

app/code/Magento/Eav/Model/Attribute/Data/Text.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function validateValue($value)
7979
return $errors;
8080
}
8181

82+
// if string with diacritics encode it.
83+
$value = $this->encodeDiacritics($value);
84+
8285
$validateLengthResult = $this->validateLength($attribute, $value);
8386
$errors = array_merge($errors, $validateLengthResult);
8487

@@ -173,4 +176,19 @@ private function validateInputRule(string $value): array
173176
$result = $this->_validateInputRule($value);
174177
return \is_array($result) ? $result : [];
175178
}
179+
180+
/**
181+
* Encode strings with diacritics for validate.
182+
*
183+
* @param array|string $value
184+
* @return array|string
185+
*/
186+
private function encodeDiacritics($value): array|string
187+
{
188+
$encoded = $value;
189+
if (is_string($value)) {
190+
$encoded = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
191+
}
192+
return $encoded;
193+
}
176194
}

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/TextTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ public function alphanumWithSpacesDataProvider(): array
199199
];
200200
}
201201

202+
/**
203+
* Test for string with diacritics validation
204+
*/
205+
public function testValidateValueStringWithDiacritics(): void
206+
{
207+
$inputValue = "á â à å ä ð é ê è ë í î ì ï ó ô ò ø õ ö ú û ù ü æ œ ç ß a ĝ ń ŕ ý ð ñ";
208+
$expectedResult = true;
209+
self::assertEquals($expectedResult, $this->model->validateValue($inputValue));
210+
}
211+
202212
/**
203213
* @param array $attributeData
204214
* @return Attribute

0 commit comments

Comments
 (0)