Jump to content

Product creation - URL deletes accent character instead of replacing it


kokosmin

Recommended Posts

Prestashop 1.7.7.8

The character deleted from title to URL is ”ț” and is not replaced with ”t”. The character successfully replaces now is ”ţ” which is the wrong character for Romanian and should not be not present in ro-RO character table or at least added with the ”ț”.

I can see why it would be present, but it's an old variant used in Windows XP default fonts.
To be clear, cedilla ț    is not correct in Romanian   https://en.wikipedia.org/wiki/Cedilla

Link to comment
Share on other sites

  • 4 months later...

In a few words, the tools.php file located in the /classes folder must be overwritten.
I can send you step-by-step instructions in a few hours, including the file in question.
Keep in mind, however, that this solution is only valid for prestashop 1.7.
If you have upgraded to prestashop 8 it will not work


 

Link to comment
Share on other sites

I don't no why but i can't attach the file.
So, I will explain below how to solve this: 
1. Using an editor (eg. notepad++), create a blank file and  paste the code below:

<?php

class Tools extends ToolsCore
{
    public static function str2url($str)
    {
        static $array_str = [];
        static $allow_accented_chars = null;
		$str = str_replace(array('Ș', 'ș', 'Ț', 'ț'), array('S', 's', 'T', 't'), $str);
        static $has_mb_strtolower = null;

        if ($has_mb_strtolower === null) {
            $has_mb_strtolower = function_exists('mb_strtolower');
        }

        if (!is_string($str)) {
            return false;
        }

        if (isset($array_str[$str])) {
            return $array_str[$str];
        }

        if ($str == '') {
            return '';
        }

        if ($allow_accented_chars === null) {
            $allow_accented_chars = Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
        }

        $return_str = trim($str);

        if ($has_mb_strtolower) {
            $return_str = mb_strtolower($return_str, 'utf-8');
        }
        if (!$allow_accented_chars) {
            $return_str = Tools::replaceAccentedChars($return_str);
        }

        // Remove all non-whitelist chars.
        if ($allow_accented_chars) {
            $return_str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]\-\p{L}]/u', '', $return_str);
        } else {
            $return_str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]\-]/', '', $return_str);
        }

        $return_str = preg_replace('/[\s\'\:\/\[\]\-]+/', ' ', $return_str);
        $return_str = str_replace([' ', '/'], '-', $return_str);

        // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations.
        // This way we lose fewer special chars.
        if (!$has_mb_strtolower) {
            $return_str = Tools::strtolower($return_str);
        }

        $array_str[$str] = $return_str;

        return $return_str;
    }
}


2. Save the file on your computer, choosing "PHP Hypertext Preprocessor" (.php) as type and name it "Tools".
3.Copy the saved file into "yourdomain.ro\override\classes\'
4. Go to BackOffice->Advanced parameters->Performance and clear cache.
5. Test your product url.
That's it

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...