Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use transliterator_transliterate to generate "url_key" #4315

Merged
merged 32 commits into from
Nov 29, 2024

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Oct 27, 2024

Description (*)

@luigifab had a great idea to use intl-extension for generating url key with translating all special chars. For me the PR did not work, so tried myself.

This is a non-BC-breaking try of it. It does not change method-signaturer and should be BC-safe. (I did not add all features of #1631. That could be done in another PR.)

To not reinvent the wheel for locale-mapping if have added symfony/string that exactly does what we need.

See: https://symfony.com/doc/current/string.html#slugger

Related Pull Requests

  1. See Used transliterator_transliterate to generate url_key #1631

Manual testing scenarios (*)

  • have multiple store with different languages assigned (eg sample data)
  • edit product title to have some locale specific character/words
    • de_DE: umlauts (äöü)
    • use trademark/copyright/etc.
  • generate new url-key (e.g. changing name) ...

Test product/category before and after ...

$urlKey = 'a & B, x%, ä, ö, ü';
$model = new Mage_Catalog_Model_Product_Url();
if (method_exists($model, 'setLocale')) {
    # $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, <store_id>);
    $model->setLocale('de_DE');
}
var_dump($model->formatUrlKey($urlKey));

Before url-key

'a-b-x-a-o-u'

After url-key

en_US
a-and-b-x-percent-a-o-u
de_DE
a-und-b-x-prozent-ae-oe-ue

Questions or comments

Locale config in xml should be changed to not have language-specif config in core. Any ideas?

Magento already had an unsused config for it ... Mage_Catalog_Helper_Product_Url::__construct looks for Mage::getConfig()->getNode('default/url/convert'); XML.

@github-actions github-actions bot added Component: Core Relates to Mage_Core Component: Catalog Relates to Mage_Catalog Component: ImportExport Relates to Mage_ImportExport composer Relates to composer.json labels Oct 27, 2024
@sreichel sreichel marked this pull request as draft October 27, 2024 16:12
@sreichel sreichel marked this pull request as ready for review October 27, 2024 17:00
@sreichel sreichel changed the title Used transliterator_transliterate to generate "url_key" Use transliterator_transliterate to generate "url_key" Oct 27, 2024
# Conflicts:
#	tests/unit/Mage/Catalog/Model/CategoryTest.php
#	tests/unit/Mage/Catalog/Model/ProductTest.php
#	tests/unit/Mage/Catalog/Model/UrlTest.php
@fballiano
Copy link
Contributor

#1631 is already merged since many months, what is the point of creating this PR when next should be released? or maybe not? this PR, if merged, will create discrepancies between the branches since IMHO do not have any reasons to exist.

@fballiano
Copy link
Contributor

@colinmollenhour

@fballiano
Copy link
Contributor

I tested it on next and it was working for me.

and anyway your answer doesn't answer my question.

@colinmollenhour

@sreichel
Copy link
Contributor Author

@fballiano

It formated the titles as explained, to default latin something, but localization never worked.

This code does not work ... b/c there is no de-de_Latn/BGN

            $opts = transliterator_list_ids();
            $code = str_replace('_', '-', strtolower($locale)) . '_Latn/BGN';
            if (in_array($code, $opts)) {

this PR, if merged, will create discrepancies between the branches since IMHO do not have any reasons to exist.

imho next branch has a not working PR in, that has to be fixed/replaced.

@colinmollenhour
Copy link
Member

@sreichel Can you confirm if the feature is working in next? Why do we need to backport it to main? It is a BC so it should not be backported from my view as it is more of a feature than a bugfix considering the old way was accepted for many years.

@sreichel
Copy link
Contributor Author

Its not a backport.

#1631 in next branch does not work. It only replaces some chars as state in the PRs description.

The code mentioned in https://github.com/OpenMage/magento-lts/pull/1631/files#diff-34c65e6986a386387a7489be1bb073b8b5e3f98e85cdf6e61804c3e309a56038R72-R78 does not work.

This PR changes no method signatures and should be BC-safe.

@colinmollenhour
Copy link
Member

This PR changes no method signatures and should be BC-safe.

But doesn't it change the url slugs? Would you consider that BC?

# Conflicts:
#	composer.lock
#	tests/unit/Mage/Catalog/Helper/Product/UrlTest.php
@sreichel
Copy link
Contributor Author

sreichel commented Nov 22, 2024

Slugs should only get generated when changing url-keys.

@sreichel sreichel marked this pull request as ready for review November 22, 2024 19:37
kiatng
kiatng previously approved these changes Nov 26, 2024
Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested.

Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections, just wanted to make sure it didn't affect existing data. I haven't tested or reviewed thoroughly, but looks good from a quick skim.

# Conflicts:
#	composer.lock
kiatng
kiatng previously approved these changes Nov 28, 2024
# Conflicts:
#	app/code/core/Mage/Catalog/Model/Category/Url.php
#	tests/unit/Mage/Catalog/Helper/Product/UrlTest.php
@sreichel sreichel requested a review from kiatng November 28, 2024 18:35
@sreichel sreichel merged commit 89c7670 into OpenMage:main Nov 29, 2024
21 checks passed
@sreichel sreichel deleted the slugger branch November 29, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog Component: Core Relates to Mage_Core Component: ImportExport Relates to Mage_ImportExport composer Relates to composer.json enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants