Skip to content

Commit 81bb39b

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop latest changes
Accepted Community Pull Requests: - #27179: improve Magento\Catalog\Model\ImageUploader error handler (by @fsw) - #26506: #26499 Always transliterate product url key (by @DanieliMi) - #27145: Cleanup ObjectManager usage - Magento_WebapiAsync (by @Bartlomiejsz) - #26959: Correctly escape custom product image attributes (by @alexander-aleman) - #25722: #25669: fixed issue "health_check.php fails if any database cache engine configured" (by @andrewbess) Fixed GitHub Issues: - #26499: Product url key is not transliterated anymore if already set (reported by @DanieliMi) has been fixed in #26506 by @DanieliMi in 2.4-develop branch Related commits: 1. e9300b7 2. b7dc0be 3. 4e54034 4. 1b3ac06 5. 55c2266 6. 27dd58a - #25219: Custom attributes of images generated by Block\Product\ImageFactory don't render correctly (reported by @chris-pook) has been fixed in #26959 by @alexander-aleman in 2.4-develop branch Related commits: 1. 6a8a103 2. 4d3a05d 3. b0ccd4f 4. 79025f8 5. 5e84595 6. afac7ea 7. c9ad76f 8. 9fa7ece - #25669: health_check.php fails if any database cache engine configured (reported by @ilnytskyi) has been fixed in #25722 by @andrewbess in 2.4-develop branch Related commits: 1. 5c121e2 2. 3905038 3. e59ee3a 4. 6633cc2
2 parents a66a2d5 + 7af4b8f commit 81bb39b

File tree

18 files changed

+294
-69
lines changed

18 files changed

+294
-69
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/AdminCreateAndEditBundleProductSettingsTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126

127127
<!-- Verify Url Key after changing -->
128128
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
129-
<argument name="productUrl" value="{{ApiBundleProduct.name}}"/>
129+
<argument name="productUrl" value="{{ApiBundleProduct.urlKey}}"/>
130130
</actionGroup>
131131

132132
<!-- Assert product design settings "Layout empty" -->

app/code/Magento/Catalog/Block/Product/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @method string getHeight()
1515
* @method string getLabel()
1616
* @method float getRatio()
17-
* @method string getCustomAttributes()
17+
* @method array getCustomAttributes()
1818
* @method string getClass()
1919
* @since 100.0.2
2020
*/

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,17 @@ public function __construct(
6868
}
6969

7070
/**
71-
* Retrieve image custom attributes for HTML element
71+
* Remove class from custom attributes
7272
*
7373
* @param array $attributes
74-
* @return string
74+
* @return array
7575
*/
76-
private function getStringCustomAttributes(array $attributes): string
76+
private function filterCustomAttributes(array $attributes): array
7777
{
78-
$result = [];
79-
foreach ($attributes as $name => $value) {
80-
if ($name != 'class') {
81-
$result[] = $name . '="' . $value . '"';
82-
}
78+
if (isset($attributes['class'])) {
79+
unset($attributes['class']);
8380
}
84-
return !empty($result) ? implode(' ', $result) : '';
81+
return $attributes;
8582
}
8683

8784
/**
@@ -170,7 +167,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
170167
'height' => $imageMiscParams['image_height'],
171168
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172169
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
173-
'custom_attributes' => $this->getStringCustomAttributes($attributes),
170+
'custom_attributes' => $this->filterCustomAttributes($attributes),
174171
'class' => $this->getClass($attributes),
175172
'product_id' => $product->getId()
176173
],

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
236236
$storage->put($baseImagePath, $content);
237237

238238
} catch (\Exception $e) {
239+
$this->logger->critical($e);
239240
throw new \Magento\Framework\Exception\LocalizedException(
240-
__('Something went wrong while saving the file(s).')
241+
__('Something went wrong while saving the file(s).'),
242+
$e
241243
);
242244
}
243245

@@ -291,7 +293,8 @@ public function saveFileToTmpDir($fileId)
291293
} catch (\Exception $e) {
292294
$this->logger->critical($e);
293295
throw new \Magento\Framework\Exception\LocalizedException(
294-
__('Something went wrong while saving the file(s).')
296+
__('Something went wrong while saving the file(s).'),
297+
$e
295298
);
296299
}
297300
}

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageFactoryTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function getTestDataWithoutAttributes(): array
145145
'height' => 100,
146146
'label' => 'test_image_label',
147147
'ratio' => 1,
148-
'custom_attributes' => '',
148+
'custom_attributes' => [],
149149
'product_id' => null,
150150
'class' => 'product-image-photo'
151151
],
@@ -203,7 +203,10 @@ private function getTestDataWithAttributes(): array
203203
'height' => 50,
204204
'label' => 'test_product_name',
205205
'ratio' => 0.5, // <==
206-
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
206+
'custom_attributes' => [
207+
'name_1' => 'value_1',
208+
'name_2' => 'value_2',
209+
],
207210
'product_id' => null,
208211
'class' => 'my-class'
209212
],

app/code/Magento/Catalog/view/frontend/templates/product/image.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
?>
1111

1212
<img class="photo image <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
13-
<?= $escaper->escapeHtml($block->getCustomAttributes()) ?>
13+
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
14+
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"
15+
<?php endforeach; ?>
1416
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
1517
loading="lazy"
1618
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"

app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<span class="product-image-wrapper"
1515
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
1616
<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
17-
<?= $escaper->escapeHtmlAttr($block->getCustomAttributes()) ?>
17+
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
18+
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"
19+
<?php endforeach; ?>
1820
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
1921
loading="lazy"
2022
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"

app/code/Magento/CatalogUrlRewrite/Model/ProductUrlPathGenerator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogUrlRewrite\Model;
89

9-
use Magento\Store\Model\Store;
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Model\Category;
1212
use Magento\Catalog\Model\Product;
13-
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
1413
use Magento\Framework\App\Config\ScopeConfigInterface;
1514
use Magento\Store\Model\ScopeInterface;
1615
use Magento\Store\Model\StoreManagerInterface;
1716

1817
/**
19-
* Class ProductUrlPathGenerator
18+
* Model product url path generator
2019
*/
2120
class ProductUrlPathGenerator
2221
{
@@ -150,7 +149,7 @@ protected function prepareProductUrlKey(Product $product)
150149
$urlKey = (string)$product->getUrlKey();
151150
$urlKey = trim(strtolower($urlKey));
152151

153-
return $urlKey ?: $product->formatUrlKey($product->getName());
152+
return $product->formatUrlKey($urlKey ?: $product->getName());
154153
}
155154

156155
/**
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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\CatalogUrlRewrite\Setup\Patch\Data;
9+
10+
use Magento\Catalog\Model\Product\Url;
11+
use Magento\Eav\Setup\EavSetup;
12+
use Magento\Eav\Setup\EavSetupFactory;
13+
use Magento\Framework\Setup\ModuleDataSetupInterface;
14+
use Magento\Framework\Setup\Patch\DataPatchInterface;
15+
use Magento\Framework\Setup\Patch\PatchVersionInterface;
16+
17+
/**
18+
* Update url_key all products.
19+
*/
20+
class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterface
21+
{
22+
/**
23+
* @var ModuleDataSetupInterface
24+
*/
25+
private $moduleDataSetup;
26+
27+
/**
28+
* @var EavSetup
29+
*/
30+
private $eavSetup;
31+
32+
/**
33+
* @var Url
34+
*/
35+
private $urlProduct;
36+
37+
/**
38+
* @param ModuleDataSetupInterface $moduleDataSetup
39+
* @param EavSetupFactory $eavSetupFactory
40+
* @param Url $urlProduct
41+
*/
42+
public function __construct(
43+
ModuleDataSetupInterface $moduleDataSetup,
44+
EavSetupFactory $eavSetupFactory,
45+
Url $urlProduct
46+
) {
47+
$this->moduleDataSetup = $moduleDataSetup;
48+
$this->eavSetup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);
49+
$this->urlProduct = $urlProduct;
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
public function apply()
56+
{
57+
$productTypeId = $this->eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
58+
$table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
59+
$select = $this->moduleDataSetup->getConnection()->select()->from(
60+
$table,
61+
['value_id', 'value']
62+
)->where(
63+
'attribute_id = ?',
64+
$this->eavSetup->getAttributeId($productTypeId, 'url_key')
65+
);
66+
67+
$result = $this->moduleDataSetup->getConnection()->fetchAll($select);
68+
foreach ($result as $key => $item) {
69+
$result[$key]['value'] = $this->urlProduct->formatUrlKey($item['value']);
70+
}
71+
72+
foreach (array_chunk($result, 500, true) as $pathResult) {
73+
$this->moduleDataSetup->getConnection()->insertOnDuplicate($table, $pathResult, ['value']);
74+
}
75+
76+
return $this;
77+
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
public static function getVersion()
83+
{
84+
return "2.4.0";
85+
}
86+
87+
/**
88+
* @inheritdoc
89+
*/
90+
public static function getDependencies()
91+
{
92+
return [];
93+
}
94+
95+
/**
96+
* @inheritdoc
97+
*/
98+
public function getAliases()
99+
{
100+
return [];
101+
}
102+
}

0 commit comments

Comments
 (0)