Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-devel…
Browse files Browse the repository at this point in the history
…op 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
  • Loading branch information
magento-engcom-team authored Mar 15, 2020
2 parents a66a2d5 + 7af4b8f commit 81bb39b
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

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

<!-- Assert product design settings "Layout empty" -->
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @method string getHeight()
* @method string getLabel()
* @method float getRatio()
* @method string getCustomAttributes()
* @method array getCustomAttributes()
* @method string getClass()
* @since 100.0.2
*/
Expand Down
17 changes: 7 additions & 10 deletions app/code/Magento/Catalog/Block/Product/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,17 @@ public function __construct(
}

/**
* Retrieve image custom attributes for HTML element
* Remove class from custom attributes
*
* @param array $attributes
* @return string
* @return array
*/
private function getStringCustomAttributes(array $attributes): string
private function filterCustomAttributes(array $attributes): array
{
$result = [];
foreach ($attributes as $name => $value) {
if ($name != 'class') {
$result[] = $name . '="' . $value . '"';
}
if (isset($attributes['class'])) {
unset($attributes['class']);
}
return !empty($result) ? implode(' ', $result) : '';
return $attributes;
}

/**
Expand Down Expand Up @@ -170,7 +167,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
'height' => $imageMiscParams['image_height'],
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
'custom_attributes' => $this->getStringCustomAttributes($attributes),
'custom_attributes' => $this->filterCustomAttributes($attributes),
'class' => $this->getClass($attributes),
'product_id' => $product->getId()
],
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Catalog/Model/ImageUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
$storage->put($baseImagePath, $content);

} catch (\Exception $e) {
$this->logger->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(
__('Something went wrong while saving the file(s).')
__('Something went wrong while saving the file(s).'),
$e
);
}

Expand Down Expand Up @@ -291,7 +293,8 @@ public function saveFileToTmpDir($fileId)
} catch (\Exception $e) {
$this->logger->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(
__('Something went wrong while saving the file(s).')
__('Something went wrong while saving the file(s).'),
$e
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function getTestDataWithoutAttributes(): array
'height' => 100,
'label' => 'test_image_label',
'ratio' => 1,
'custom_attributes' => '',
'custom_attributes' => [],
'product_id' => null,
'class' => 'product-image-photo'
],
Expand Down Expand Up @@ -203,7 +203,10 @@ private function getTestDataWithAttributes(): array
'height' => 50,
'label' => 'test_product_name',
'ratio' => 0.5, // <==
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
'custom_attributes' => [
'name_1' => 'value_1',
'name_2' => 'value_2',
],
'product_id' => null,
'class' => 'my-class'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
?>

<img class="photo image <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?= $escaper->escapeHtml($block->getCustomAttributes()) ?>
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"
<?php endforeach; ?>
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
loading="lazy"
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<span class="product-image-wrapper"
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
<img class="<?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?= $escaper->escapeHtmlAttr($block->getCustomAttributes()) ?>
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"
<?php endforeach; ?>
src="<?= $escaper->escapeUrl($block->getImageUrl()) ?>"
loading="lazy"
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model;

use Magento\Store\Model\Store;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class ProductUrlPathGenerator
* Model product url path generator
*/
class ProductUrlPathGenerator
{
Expand Down Expand Up @@ -150,7 +149,7 @@ protected function prepareProductUrlKey(Product $product)
$urlKey = (string)$product->getUrlKey();
$urlKey = trim(strtolower($urlKey));

return $urlKey ?: $product->formatUrlKey($product->getName());
return $product->formatUrlKey($urlKey ?: $product->getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Setup\Patch\Data;

use Magento\Catalog\Model\Product\Url;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

/**
* Update url_key all products.
*/
class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @var EavSetup
*/
private $eavSetup;

/**
* @var Url
*/
private $urlProduct;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
* @param Url $urlProduct
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory,
Url $urlProduct
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);
$this->urlProduct = $urlProduct;
}

/**
* @inheritdoc
*/
public function apply()
{
$productTypeId = $this->eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
$select = $this->moduleDataSetup->getConnection()->select()->from(
$table,
['value_id', 'value']
)->where(
'attribute_id = ?',
$this->eavSetup->getAttributeId($productTypeId, 'url_key')
);

$result = $this->moduleDataSetup->getConnection()->fetchAll($select);
foreach ($result as $key => $item) {
$result[$key]['value'] = $this->urlProduct->formatUrlKey($item['value']);
}

foreach (array_chunk($result, 500, true) as $pathResult) {
$this->moduleDataSetup->getConnection()->insertOnDuplicate($table, $pathResult, ['value']);
}

return $this;
}

/**
* @inheritDoc
*/
public static function getVersion()
{
return "2.4.0";
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}
}
Loading

0 comments on commit 81bb39b

Please sign in to comment.