Skip to content

Commit c2a7ad4

Browse files
committed
Merge branch 'ACP2E-345' of https://github.com/magento-l3/magento2ce into L3-PR-2022-04-19-v2
2 parents a8b38d5 + b1e4b39 commit c2a7ad4

File tree

6 files changed

+159
-2
lines changed

6 files changed

+159
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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\Catalog\Setup\Patch\Data;
9+
10+
use Magento\Eav\Setup\EavSetup;
11+
use Magento\Eav\Setup\EavSetupFactory;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Framework\Setup\Patch\DataPatchInterface;
14+
use Magento\Framework\Setup\Patch\PatchVersionInterface;
15+
16+
/**
17+
* Class UpdateProductUrlKey for updating description and validation class
18+
*/
19+
class UpdateProductUrlKey implements DataPatchInterface, PatchVersionInterface
20+
{
21+
/**
22+
* @var ModuleDataSetupInterface
23+
*/
24+
private $moduleDataSetup;
25+
26+
/**
27+
* @var EavSetupFactory
28+
*/
29+
private $eavSetupFactory;
30+
31+
/**
32+
* PatchInitial constructor.
33+
* @param ModuleDataSetupInterface $moduleDataSetup
34+
* @param EavSetupFactory $eavSetupFactory
35+
*/
36+
public function __construct(
37+
ModuleDataSetupInterface $moduleDataSetup,
38+
EavSetupFactory $eavSetupFactory
39+
) {
40+
$this->moduleDataSetup = $moduleDataSetup;
41+
$this->eavSetupFactory = $eavSetupFactory;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function apply()
48+
{
49+
/** @var EavSetup $eavSetup */
50+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
51+
52+
$eavSetup->updateAttribute(
53+
\Magento\Catalog\Model\Product::ENTITY,
54+
'url_key',
55+
[
56+
'frontend_class' => 'validate-trailing-hyphen'
57+
]
58+
);
59+
return $this;
60+
}
61+
62+
/**
63+
* @inheritdoc
64+
*/
65+
public static function getDependencies()
66+
{
67+
return [
68+
UpdateProductAttributes::class,
69+
\Magento\CatalogUrlRewrite\Setup\Patch\Data\CreateUrlAttributes::class
70+
];
71+
}
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public static function getVersion()
77+
{
78+
return '2.4.5';
79+
}
80+
81+
/**
82+
* @inheritdoc
83+
*/
84+
public function getAliases()
85+
{
86+
return [];
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminCreateSimpleProductUrlKeyTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Validate URL key while creating Product via Admin"/>
14+
<title value="Admin user should be informed and restricted on allowed characters in URL Key"/>
15+
<description value="User was not being informed about the allowed characters in the UI for URL Key, but later the URL key was getting trimmed in backend"/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="AC-2585"/>
18+
<useCaseId value="ACP2E-345"/>
19+
<group value="product"/>
20+
</annotations>
21+
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
23+
<actionGroup ref="AdminOpenNewProductFormPageActionGroup" stepKey="goToCreateProduct"/>
24+
25+
<!--Trigger SEO drop down-->
26+
<scrollTo selector="{{AdminProductSEOSection.sectionHeader}}" x="0" y="-80" stepKey="scrollToSearchEngineOptimization"/>
27+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="selectSearchEngineOptimization"/>
28+
<waitForPageLoad stepKey="WaitForDropDownSEO"/>
29+
30+
<fillField stepKey="fillUrlKey1" selector="{{AdminProductFormBundleSection.urlKey}}" userInput="example-page-"/>
31+
<click stepKey="blurFromUrlKey1" selector="{{AdminProductSEOSection.metaTitleInput}}"/>
32+
<see selector="{{AdminProductFormSection.fieldError('url_key')}}" userInput="Trailing hyphens are not allowed." stepKey="seeLastHyphenErrorMessage"/>
33+
34+
<clearField selector="{{AdminProductFormBundleSection.urlKey}}" stepKey="clearFieldUrlKey2"/>
35+
<fillField stepKey="fillUrlKey2" selector="{{AdminProductFormBundleSection.urlKey}}" userInput="-Example-Page"/>
36+
<click stepKey="blurFromUrlKey2" selector="{{AdminProductSEOSection.metaTitleInput}}"/>
37+
<see selector="{{AdminProductFormSection.fieldError('url_key')}}" userInput="Trailing hyphens are not allowed." stepKey="seeFirstHyphenErrorMessage"/>
38+
39+
<clearField selector="{{AdminProductFormBundleSection.urlKey}}" stepKey="clearFieldUrlKey3"/>
40+
<click stepKey="blurFromUrlKey3" selector="{{AdminProductSEOSection.metaTitleInput}}"/>
41+
<fillField stepKey="fillUrlKey3" selector="{{AdminProductFormBundleSection.urlKey}}" userInput="example-page-test"/>
42+
<dontSee selector="{{AdminProductFormSection.fieldError('url_key')}}" userInput="Trailing hyphens are not allowed." stepKey="dontSeeErrorMessage"/>
43+
</test>
44+
</tests>

app/code/Magento/Catalog/Ui/DataProvider/CatalogEavValidationRules.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected function mapRules($class, array $rules)
7070
case 'validate-digits':
7171
case 'validate-email':
7272
case 'validate-url':
73+
case 'validate-trailing-hyphen':
7374
case 'validate-alpha':
7475
case 'validate-alphanum':
7576
$rules = array_merge($rules, [$class => true]);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,31 @@ protected function customizeNameListeners(array $meta)
389389
);
390390

391391
$namePath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_NAME, $meta, null, 'children');
392-
393-
return $this->arrayManager->merge(
392+
$meta = $this->arrayManager->merge(
394393
$namePath . static::META_CONFIG_PATH,
395394
$meta,
396395
[
397396
'valueUpdate' => 'keyup'
398397
]
399398
);
399+
400+
$urlKeyConfig = [
401+
'tooltip' => [
402+
'link' => 'https://docs.magento.com/user-guide/catalog/catalog-urls.html',
403+
'description' => __(
404+
'The URL key should consist of lowercase characters with hyphens to separate words.'
405+
),
406+
],
407+
];
408+
409+
$urkKeyPath = $this->arrayManager->findPath(
410+
ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY,
411+
$meta,
412+
null,
413+
'children'
414+
);
415+
416+
return $this->arrayManager->merge($urkKeyPath . static::META_CONFIG_PATH, $meta, $urlKeyConfig);
400417
}
401418

402419
/**

app/code/Magento/Ui/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Keyword,Keyword
105105
"Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.","Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed."
106106
"Please enter a valid date.","Please enter a valid date."
107107
"Please enter a valid URL Key (Ex: ""example-page"", ""example-page.html"" or ""anotherlevel/example-page"").","Please enter a valid URL Key (Ex: ""example-page"", ""example-page.html"" or ""anotherlevel/example-page"")."
108+
"Trailing hyphens are not allowed.","Trailing hyphens are not allowed."
108109
"Please enter a valid zip code.","Please enter a valid zip code."
109110
"Please select State/Province.","Please select State/Province."
110111
"Please enter a value less than or equal to {0}.","Please enter a value less than or equal to {0}."

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,12 @@ define([
817817
},
818818
$.mage.__('Please enter a valid URL Key (Ex: "example-page", "example-page.html" or "anotherlevel/example-page").')//eslint-disable-line max-len
819819
],
820+
'validate-trailing-hyphen': [
821+
function (value) {
822+
return utils.isEmptyNoTrim(value) || /^(?!-)(?!.*-$).+$/.test(value);
823+
},
824+
$.mage.__('Trailing hyphens are not allowed.')
825+
],
820826
'validate-zip-international': [
821827

822828
/*function(v) {

0 commit comments

Comments
 (0)