Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/2.4-develop' into 2.4-develop-…
Browse files Browse the repository at this point in the history
…pr16
  • Loading branch information
serhii-balko committed Mar 16, 2020
2 parents 5fe9df0 + 81bb39b commit 22957d7
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 22957d7

Please sign in to comment.