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

Fixed bug, incorrect auto-generation Category URL for some groups of symbols (idish, cirrilic, é, ä, and other). #491

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions app/code/Magento/Catalog/Helper/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,4 @@ public function getConvertTable()
return $this->_convertTable;
}

/**
* Process string based on convertation table
*
* @param string $string
* @return string
*/
public function format($string)
{
$string = strtr($string, $this->getConvertTable());
return '"libiconv"' == ICONV_IMPL
? iconv(\Magento\Stdlib\String::ICONV_CHARSET, 'ascii//ignore//translit', $string)
: $string;
}
}
18 changes: 7 additions & 11 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ class Category extends \Magento\Catalog\Model\AbstractModel
protected $_catalogCategoryFlat = null;

/**
* Core data
* Static URL Format instance
*
* @var \Magento\Filter\FilterManager
* @var \Magento\Url\Helper\Format
*/
protected $filter;

protected $_urlFormat;
/**
* Index indexer
*
Expand Down Expand Up @@ -209,7 +209,7 @@ public function __construct(
\Magento\Index\Model\Indexer $indexIndexer,
\Magento\Core\Helper\Data $coreData,
\Magento\Catalog\Helper\Category\Flat $catalogCategoryFlat,
\Magento\Filter\FilterManager $filter,
\Magento\Url\Helper\Format $urlFormat,
\Magento\Core\Model\Resource\AbstractResource $resource = null,
\Magento\Data\Collection\Db $resourceCollection = null,
array $data = array()
Expand All @@ -222,7 +222,7 @@ public function __construct(
$this->_productCollectionFactory = $productCollectionFactory;
$this->_catalogConfig = $catalogConfig;
$this->_indexIndexer = $indexIndexer;
$this->filter = $filter;
$this->_urlFormat = $urlFormat;
$this->_catalogCategoryFlat = $catalogCategoryFlat;
$this->_treeModel = $categoryTreeResource;
parent::__construct($context, $registry, $storeManager, $resource, $resourceCollection, $data);
Expand Down Expand Up @@ -566,11 +566,7 @@ public function getCategoryIdUrl()
*/
public function formatUrlKey($str)
{
$str = $this->filter->removeAccents($str);
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', $str);
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');
return $urlKey;
return $this->_urlFormat->formatUrlKey($str);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions app/code/Magento/Catalog/Model/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class Url extends \Magento\Object
*/
protected $_url;

/**
* Static URL Format instance
*
* @var \Magento\Url\Helper\Format
*/
protected $_urlFormat;

/**
* Static URL Rewrite Instance
*
Expand Down Expand Up @@ -92,6 +99,7 @@ class Url extends \Magento\Object
public function __construct(
\Magento\Core\Model\Url\RewriteFactory $urlRewriteFactory,
\Magento\UrlInterface $url,
\Magento\Url\Helper\Format $urlformat,
\Magento\Core\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Helper\Category $catalogCategory,
\Magento\Catalog\Helper\Product\Url $catalogProductUrl,
Expand All @@ -100,6 +108,7 @@ public function __construct(
) {
$this->_urlRewrite = $urlRewriteFactory->create();
$this->_url = $url;
$this->_urlFormat = $urlformat;
$this->_storeManager = $storeManager;
$this->_catalogCategory = $catalogCategory;
$this->_catalogProductUrl = $catalogProductUrl;
Expand Down Expand Up @@ -183,11 +192,7 @@ public function getProductUrl($product, $useSid = null)
*/
public function formatUrlKey($str)
{
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', $this->_catalogProductUrl->format($str));
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');

return $urlKey;
return $this->_urlFormat->formatUrlKey($str);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ protected function _prepareForm()
'name' => 'identifier',
'label' => __('URL Key'),
'title' => __('URL Key'),
'required' => true,
'class' => 'validate-identifier',
'note' => __('Relative to Web Site Base URL'),
'disabled' => $isElementDisabled
Expand Down
26 changes: 25 additions & 1 deletion app/code/Magento/Cms/Model/Resource/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Page extends \Magento\Core\Model\Resource\Db\AbstractDb
*/
protected $dateTime;

/**
* Static URL Format instance
*
* @var \Magento\Url\Helper\Format
*/
protected $_urlFormat;

/**
* Construct
*
Expand All @@ -72,12 +79,14 @@ public function __construct(
\Magento\App\Resource $resource,
\Magento\Core\Model\Date $date,
\Magento\Core\Model\StoreManagerInterface $storeManager,
\Magento\Stdlib\DateTime $dateTime
\Magento\Stdlib\DateTime $dateTime,
\Magento\Url\Helper\Format $urlFormat
) {
parent::__construct($resource);
$this->_date = $date;
$this->_storeManager = $storeManager;
$this->dateTime = $dateTime;
$this->_urlFormat = $urlFormat;
}

/**
Expand Down Expand Up @@ -126,6 +135,10 @@ protected function _beforeSave(\Magento\Core\Model\AbstractModel $object)
$object->setData($field, $this->dateTime->formatDate($value));
}

if (!$object->getData('identifier')) {
$object->setData('identifier', $this->formatUrlKey($object->getData('title')));
}

if (!$this->getIsUniquePageToStores($object)) {
throw new \Magento\Core\Exception(__('A page URL key for specified store already exists.'));
}
Expand Down Expand Up @@ -453,4 +466,15 @@ public function getStore()
{
return $this->_storeManager->getStore($this->_store);
}

/**
* Format Key for URL
*
* @param string $str
* @return string
*/
public function formatUrlKey($str)
{
return $this->_urlFormat->formatUrlKey($str);
}
}
154 changes: 154 additions & 0 deletions app/code/Magento/Url/Helper/Format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Magento
* @package Magento_Catalog
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


/**
* Url helper
*
* @category Magento
* @package Magento_Url
* @author Magento Core Team <[email protected]>
*/
namespace Magento\Url\Helper;

class Format extends \Magento\App\Helper\AbstractHelper
{
/**
* Symbol convert table
*
* @var array
*/
protected $_convertTable = array(
'&amp;' => 'and', '@' => 'at', '©' => 'c', '®' => 'r', 'À' => 'a',
'Á' => 'a', 'Â' => 'a', 'Ä' => 'a', 'Å' => 'a', 'Æ' => 'ae','Ç' => 'c',
'È' => 'e', 'É' => 'e', 'Ë' => 'e', 'Ì' => 'i', 'Í' => 'i', 'Î' => 'i',
'Ï' => 'i', 'Ò' => 'o', 'Ó' => 'o', 'Ô' => 'o', 'Õ' => 'o', 'Ö' => 'o',
'Ø' => 'o', 'Ù' => 'u', 'Ú' => 'u', 'Û' => 'u', 'Ü' => 'u', 'Ý' => 'y',
'ß' => 'ss','à' => 'a', 'á' => 'a', 'â' => 'a', 'ä' => 'a', 'å' => 'a',
'æ' => 'ae','ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e',
'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ò' => 'o', 'ó' => 'o',
'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u',
'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'þ' => 'p', 'ÿ' => 'y', 'Ā' => 'a',
'ā' => 'a', 'Ă' => 'a', 'ă' => 'a', 'Ą' => 'a', 'ą' => 'a', 'Ć' => 'c',
'ć' => 'c', 'Ĉ' => 'c', 'ĉ' => 'c', 'Ċ' => 'c', 'ċ' => 'c', 'Č' => 'c',
'č' => 'c', 'Ď' => 'd', 'ď' => 'd', 'Đ' => 'd', 'đ' => 'd', 'Ē' => 'e',
'ē' => 'e', 'Ĕ' => 'e', 'ĕ' => 'e', 'Ė' => 'e', 'ė' => 'e', 'Ę' => 'e',
'ę' => 'e', 'Ě' => 'e', 'ě' => 'e', 'Ĝ' => 'g', 'ĝ' => 'g', 'Ğ' => 'g',
'ğ' => 'g', 'Ġ' => 'g', 'ġ' => 'g', 'Ģ' => 'g', 'ģ' => 'g', 'Ĥ' => 'h',
'ĥ' => 'h', 'Ħ' => 'h', 'ħ' => 'h', 'Ĩ' => 'i', 'ĩ' => 'i', 'Ī' => 'i',
'ī' => 'i', 'Ĭ' => 'i', 'ĭ' => 'i', 'Į' => 'i', 'į' => 'i', 'İ' => 'i',
'ı' => 'i', 'IJ' => 'ij','ij' => 'ij','Ĵ' => 'j', 'ĵ' => 'j', 'Ķ' => 'k',
'ķ' => 'k', 'ĸ' => 'k', 'Ĺ' => 'l', 'ĺ' => 'l', 'Ļ' => 'l', 'ļ' => 'l',
'Ľ' => 'l', 'ľ' => 'l', 'Ŀ' => 'l', 'ŀ' => 'l', 'Ł' => 'l', 'ł' => 'l',
'Ń' => 'n', 'ń' => 'n', 'Ņ' => 'n', 'ņ' => 'n', 'Ň' => 'n', 'ň' => 'n',
'ʼn' => 'n', 'Ŋ' => 'n', 'ŋ' => 'n', 'Ō' => 'o', 'ō' => 'o', 'Ŏ' => 'o',
'ŏ' => 'o', 'Ő' => 'o', 'ő' => 'o', 'Œ' => 'oe','œ' => 'oe','Ŕ' => 'r',
'ŕ' => 'r', 'Ŗ' => 'r', 'ŗ' => 'r', 'Ř' => 'r', 'ř' => 'r', 'Ś' => 's',
'ś' => 's', 'Ŝ' => 's', 'ŝ' => 's', 'Ş' => 's', 'ş' => 's', 'Š' => 's',
'š' => 's', 'Ţ' => 't', 'ţ' => 't', 'Ť' => 't', 'ť' => 't', 'Ŧ' => 't',
'ŧ' => 't', 'Ũ' => 'u', 'ũ' => 'u', 'Ū' => 'u', 'ū' => 'u', 'Ŭ' => 'u',
'ŭ' => 'u', 'Ů' => 'u', 'ů' => 'u', 'Ű' => 'u', 'ű' => 'u', 'Ų' => 'u',
'ų' => 'u', 'Ŵ' => 'w', 'ŵ' => 'w', 'Ŷ' => 'y', 'ŷ' => 'y', 'Ÿ' => 'y',
'Ź' => 'z', 'ź' => 'z', 'Ż' => 'z', 'ż' => 'z', 'Ž' => 'z', 'ž' => 'z',
'ſ' => 'z', 'Ə' => 'e', 'ƒ' => 'f', 'Ơ' => 'o', 'ơ' => 'o', 'Ư' => 'u',
'ư' => 'u', 'Ǎ' => 'a', 'ǎ' => 'a', 'Ǐ' => 'i', 'ǐ' => 'i', 'Ǒ' => 'o',
'ǒ' => 'o', 'Ǔ' => 'u', 'ǔ' => 'u', 'Ǖ' => 'u', 'ǖ' => 'u', 'Ǘ' => 'u',
'ǘ' => 'u', 'Ǚ' => 'u', 'ǚ' => 'u', 'Ǜ' => 'u', 'ǜ' => 'u', 'Ǻ' => 'a',
'ǻ' => 'a', 'Ǽ' => 'ae','ǽ' => 'ae','Ǿ' => 'o', 'ǿ' => 'o', 'ə' => 'e',
'Ё' => 'jo','Є' => 'e', 'І' => 'i', 'Ї' => 'i', 'А' => 'a', 'Б' => 'b',
'В' => 'v', 'Г' => 'g', 'Д' => 'd', 'Е' => 'e', 'Ж' => 'zh','З' => 'z',
'И' => 'i', 'Й' => 'j', 'К' => 'k', 'Л' => 'l', 'М' => 'm', 'Н' => 'n',
'О' => 'o', 'П' => 'p', 'Р' => 'r', 'С' => 's', 'Т' => 't', 'У' => 'u',
'Ф' => 'f', 'Х' => 'h', 'Ц' => 'c', 'Ч' => 'ch','Ш' => 'sh','Щ' => 'sch',
'Ъ' => '-', 'Ы' => 'y', 'Ь' => '-', 'Э' => 'je','Ю' => 'ju','Я' => 'ja',
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e',
'ж' => 'zh','з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l',
'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's',
'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
'ш' => 'sh','щ' => 'sch','ъ' => '-','ы' => 'y', 'ь' => '-', 'э' => 'je',
'ю' => 'ju','я' => 'ja','ё' => 'jo','є' => 'e', 'і' => 'i', 'ї' => 'i',
'Ґ' => 'g', 'ґ' => 'g', 'א' => 'a', 'ב' => 'b', 'ג' => 'g', 'ד' => 'd',
'ה' => 'h', 'ו' => 'v', 'ז' => 'z', 'ח' => 'h', 'ט' => 't', 'י' => 'i',
'ך' => 'k', 'כ' => 'k', 'ל' => 'l', 'ם' => 'm', 'מ' => 'm', 'ן' => 'n',
'נ' => 'n', 'ס' => 's', 'ע' => 'e', 'ף' => 'p', 'פ' => 'p', 'ץ' => 'C',
'צ' => 'c', 'ק' => 'q', 'ר' => 'r', 'ש' => 'w', 'ת' => 't', '™' => 'tm',
);

/**
* @param \Magento\App\Helper\Context $context
* @param \Magento\App\ConfigInterface $config
*/
public function __construct(
\Magento\App\ConfigInterface $config
) {
$convertConfig = $config->getValue('url/convert', 'default');
if ($convertConfig) {
foreach ($convertConfig as $configValue) {
$this->_convertTable[strval($configValue['from'])] = strval($configValue['to']);
}
}
}

/**
* Get chars convertation table
*
* @return array
*/
protected function getConvertTable()
{
return $this->_convertTable;
}

/**
* Process string based on convertation table
*
* @param string $string
* @return string
*/
public function format($string)
{
$string = strtr($string, $this->getConvertTable());
return '"libiconv"' == ICONV_IMPL
? iconv(\Magento\Stdlib\String::ICONV_CHARSET, 'ascii//ignore//translit', $string)
: $string;
}

/**
* Formats URL key
*
* @param $string URL
* @return string
*/
public function formatUrlKey($string)
{
$urlKey = preg_replace('#[^0-9a-z]+#i', '-', $this->format($string));
$urlKey = strtolower($urlKey);
$urlKey = trim($urlKey, '-');

return $urlKey;
}

}