magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Use transliterator_transliterate to generate url_key

Open luigifab opened this issue 4 years ago • 12 comments

Description

When a product or a category url key use special characters, they are substituted with strstr. With this PR, transliteration is used (with PHP INTL).

Tested with the following locales: fr-FR, es-ES, de-DE, it-IT, pt-PT, nl-NL, pl-PL, cs-CZ, sk-SK, ru-RU, uk-UA. OpenMage 20.x / PHP 7.4.6 and 8.0.x and 8.2.x

Manual testing scenarios

  • Set default locale to French.
  • Set first store locale to Russian.
  • Set second store locale to French.
  • Create a product and category with the following name: Массажный Аппарат для Похудения A
  • Set the product and category name on first store to: Массажный Аппарат для Похудения B
  • Set the product and category name on second store to: Массажный Аппарат для Похудения C

Run:

DELETE FROM catalog_category_entity_varchar WHERE attribute_id IN (
    SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'url_key');
DELETE FROM catalog_product_entity_varchar WHERE attribute_id IN (
    SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'url_key');

Run:

rm -rf var/cache/ ; php shell/indexer.php reindexall ; rm -rf var/cache/

Check url keys generated:

  • all store views: massazhnyj-apparat-dlja-pohudenija-b
  • first store: massazhnyj-apparat-dlja-pohudenija-b
  • second store: massazhnyj-apparat-dlja-pohudenija-b

That's wrong, and not good. So apply the PR, clear existing url keys (first run), reindex and clear cache (second run).

Check url keys generated:

  • all store views: massaznyj-apparat-dla-pohudenia-a
  • first store: massazhnyy-apparat-dlya-pokhudeniya-b
  • second store: massaznyj-apparat-dla-pohudenia-c

That's better.

Extra: for CMS / Pages, when an user create a new page without url key, an url key is generated.

Contribution checklist

  • [x] Pull request has a meaningful description of its purpose
  • [x] All commits are accompanied by meaningful commit messages
  • [x] All automated tests passed successfully (all builds are green)
  • [x] Add yourself to contributors list

luigifab avatar May 20 '21 18:05 luigifab

If this is part of "intl" we've to require ext-intl in composer.json, which would also help https://github.com/OpenMage/magento-lts/pull/2411 cause we wouldn't need Net_IRDA anymore

fballiano avatar Sep 01 '22 12:09 fballiano

Is this code (#345) still required?

sreichel avatar Oct 16 '22 19:10 sreichel

You are right, the function removeAccents must be updated! I discovered it now. It seems that openmage doesn't use it?

https://github.com/OpenMage/magento-lts/blob/f48e168f15453c9771bf91f93e06c70432e2b3b0/app/code/core/Mage/Core/Helper/Data.php#L332-L389

Perhaps simply:

    public function removeAccents($string)
    {
        $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $this->getStoreId());
        return Mage::helper('catalog/product_url')->format($string, $locale);
    }

luigifab avatar Oct 20 '22 16:10 luigifab

@luigifab i'll check conflicts after weekend.

sreichel avatar Dec 02 '22 05:12 sreichel

ping @sreichel :) ?

luigifab avatar Mar 03 '23 21:03 luigifab

Sorry, no. I'm not active here anymore.

sreichel avatar Mar 04 '23 06:03 sreichel

as per https://github.com/OpenMage/rfcs/pull/7 I think this should be targeting 20.0, what do you think?

fballiano avatar Mar 04 '23 10:03 fballiano

:'( how can I change the base branch??

luigifab avatar Apr 04 '23 18:04 luigifab

:'( how can I change the base branch??

From Desktop click Edit on the top right corner then select the branch from the dropdown.

elidrissidev avatar Apr 04 '23 18:04 elidrissidev

Good! I forgot where it was.

luigifab avatar Apr 04 '23 18:04 luigifab

@luigifab since today we've to rebase to the main branch ;-)

fballiano avatar Apr 04 '23 18:04 fballiano

I like this PR but it modified the signature of a lot of public methods, so it has to be moved to the next branch and considered a breaking change

fballiano avatar Feb 28 '24 12:02 fballiano

@luigifab do you use this PR in production?

fballiano avatar Apr 19 '24 14:04 fballiano

Yes!

luigifab avatar Apr 19 '24 19:04 luigifab