Question

How should we replace common Greek characters for Magento to work on the swatches? According to what rules should we name each png file in the swatches folder? Thanks.

Was it helpful?

Solution

TL;DR: Don't use Mage_ConfigurableSwatches with Greek letters.

Magento tries to transliterate all characters to ASCII, replace remaining non word characters with hyphens and then convert the string to lowercase. The relevant code in Mage_ConfigurableSwatches_Helper_Data is:

public function getHyphenatedString($str)
{
    $result = false;
    if (function_exists('iconv')) {
        $result = @iconv('UTF-8', 'ASCII//TRANSLIT', $str); // will issue a notice on failure, we handle failure
    }
    if (!$result) {
        $result = dechex(crc32(self::normalizeKey($str)));
    }
    return preg_replace('/([^a-z0-9]+)/', '-', self::normalizeKey($result));
}

public static function normalizeKey($key) {
    if (function_exists('mb_strtolower')) {
        return trim(mb_strtolower($key, 'UTF-8'));
    }
    return trim(strtolower($key));
}

For alphabets that can be transliterated, you need to

  • have the iconv PHP extension enabled
  • have the system locale set to the language that should be used for transliteration (configure it in Magento should suffice)

Then use the transliterated version, for example:

"Döner Dürüm" => "doener-dueruem"

Unfortunately, greek letters cannot be transliterated to latin letters with iconv, so it could happen that either

  1. all sequences of greek letters are replaced with a dash

    "Test Greek αβγ" => "test-greek-"
    

or

  1. iconv returns false and the result (the expected file name) is the CRC32 checksum of the original string as a hex value.

Both outcomes are highly unusable, so I would recommend not using options with only greek letters or not use the configurable swatches from Magento.

A much better and free alternative is Easylife Switcher - same features, better user interface, not tied to the RWD theme.

OTHER TIPS

The naming convention for Magento 1.9.1 swatches is as follows:

1 ) All smaller case 2 ) Use dash to separate words

For example you have a color Royal Blue swatch is named royal-blue.png

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top