Přidání odkazů do popisů kategorií

Chtěli jste někdy vytvořit odkaz v popiscích kategorií? Jak jste již zjistili, tuto možnost Prestashop (v 1.4.) nenabízí.

Ale stejně jako mnohé další věci, se dá i toto obejít.

  1. Vytvořte soubor Category.php ve složce /override/classe

Do něj pak vložte tento text:

<?php

class Category extends CategoryCore
{
    public function getTranslationsFieldsChild() {
        self::validateFieldsLang();

        $fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
        $fields = array();
        $languages = Language::getLanguages();
        $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
        foreach ($languages as $language)
        {
            $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
            $fields[$language['id_lang']][$this->identifier] = intval($this->id);
            $fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
            foreach ($fieldsArray as $field)
            {
                if (!Validate::isTableOrIdentifier($field))
                    die(Tools::displayError());

                /* Check fields validity */
                if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
                    $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
                elseif (in_array($field, $this->fieldsRequiredLang))
                    $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
                else
                    $fields[$language['id_lang']][$field] = '';
            }
        }
        return $fields;
    }
}

 

  1. Vytvořte soubor AdminTab.php ve složce /override/classes

Soubor bude obsahovat následující kod:

<?php

class AdminTab extends AdminTabCore
{
public function displayListContent($token = NULL)
{
/* Display results in a table
*
* align  : determine value alignment
* prefix : displayed before value
* suffix : displayed after value
* image  : object image
* icon   : icon determined by values
* active : allow to toggle status
*/

global $currentIndex, $cookie;
$currency = new Currency(Configuration::get(‚PS_CURRENCY_DEFAULT‘));

$id_category = 1; // default categ

$irow = 0;
if ($this->_list AND isset($this->fieldsDisplay[‚position‘]))
{
$positions = array_map(create_function(‚$elem‘, ‚return (int)($elem[‚position‘]);‘), $this->_list);
sort($positions);
}
if ($this->_list)
{
$isCms = false;
if (preg_match(‚/cms/Ui‘, $this->identifier))
$isCms = true;
$keyToGet = ‚id_‘.($isCms ? ‚cms_‘ : “).’category‘.(in_array($this->identifier, array(‚id_category‘, ‚id_cms_category‘)) ? ‚_parent‘ : “);
foreach ($this->_list AS $tr)
{
$id = $tr[$this->identifier];
echo ‚<tr‘.(array_key_exists($this->identifier,$this->identifiersDnd) ? ‚ id=“tr_‘.(($id_category = (int)(Tools::getValue(‚id_‘.($isCms ? ‚cms_‘ : “).’category‘, ‚1‘))) ? $id_category : “).’_‘.$id.’_‘.$tr[‚position‘].'“‚ : “).($irow++ % 2 ? “ : “).‘ ‚.((isset($tr[‚color‘]) AND $this->colorOnBackground) ? ‚style=“background-color: ‚.$tr[‚color‘].'“‚ : “).‘>
<td>‘;
if ($this->delete AND (!isset($this->_listSkipDelete) OR !in_array($id, $this->_listSkipDelete)))
echo ‚<input type=“checkbox“ name=“‚.$this->table.’Box[]“ value=“‚.$id.'“ />‘;
echo ‚</td>‘;
foreach ($this->fieldsDisplay AS $key => $params)
{
$tmp = explode(‚!‘, $key);
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
echo ‚
<td ‚.(isset($params[‚position‘]) ? ‚ id=“td_‘.(isset($id_category) AND $id_category ? $id_category : 0).’_‘.$id.'“‚ : “).‘ ‚;
if (!isset($params[‚position‘]) AND (!isset($this->noLink) OR !$this->noLink))
echo ‚ onclick=“document.location = “.$currentIndex.’&‘.$this->identifier.’=‘.$id.($this->view? ‚&view‘ : ‚&update‘).$this->table.’&token=‘.($token!=NULL ? $token : $this->token).““>‘.(isset($params[‚prefix‘]) ? $params[‚prefix‘] : “);
else
echo ‚>‘;
if (isset($params[‚active‘]) AND isset($tr[$key]))
$this->_displayEnableLink($token, $id, $tr[$key], $params[‚active‘], Tools::getValue(‚id_category‘), Tools::getValue(‚id_product‘));
elseif (isset($params[‚activeVisu‘]) AND isset($tr[$key]))
echo ‚<img src=“../img/admin/‘.($tr[$key] ? ‚enabled.gif‘ : ‚disabled.gif‘).'“
alt=“‚.($tr[$key] ? $this->l(‚Enabled‘) : $this->l(‚Disabled‘)).'“ title=“‚.($tr[$key] ? $this->l(‚Enabled‘) : $this->l(‚Disabled‘)).'“ />‘;
elseif (isset($params[‚position‘]))
{
if ($this->_orderBy == ‚position‘ AND $this->_orderWay != ‚DESC‘)
{
echo ‚<a‘.(!($tr[$key] != $positions[sizeof($positions) – 1]) ? ‚ style=“display: none;“‚ : “).‘ href=“‚.$currentIndex.
‚&‘.$keyToGet.’=‘.(int)($id_category).’&‘.$this->identifiersDnd[$this->identifier].’=‘.$id.‘
&way=1&position=‘.(int)($tr[‚position‘] + 1).’&token=‘.($token!=NULL ? $token : $this->token).'“>
<img src=“../img/admin/‘.($this->_orderWay == ‚ASC‘ ? ‚down‘ : ‚up‘).‘.gif“
alt=“‚.$this->l(‚Down‘).'“ title=“‚.$this->l(‚Down‘).'“ /></a>‘;

echo ‚<a‘.(!($tr[$key] != $positions[0]) ? ‚ style=“display: none;“‚ : “).‘ href=“‚.$currentIndex.
‚&‘.$keyToGet.’=‘.(int)($id_category).’&‘.$this->identifiersDnd[$this->identifier].’=‘.$id.‘
&way=0&position=‘.(int)($tr[‚position‘] – 1).’&token=‘.($token!=NULL ? $token : $this->token).'“>
<img src=“../img/admin/‘.($this->_orderWay == ‚ASC‘ ? ‚up‘ : ‚down‘).‘.gif“
alt=“‚.$this->l(‚Up‘).'“ title=“‚.$this->l(‚Up‘).'“ /></a>‘;                        }
else
echo (int)($tr[$key] + 1);
}
elseif (isset($params[‚image‘]))
{
// item_id is the product id in a product image context, else it is the image id.
$item_id = isset($params[‚image_id‘]) ? $tr[$params[‚image_id‘]] : $id;
// If it’s a product image
if (isset($tr[‚id_image‘]))
{
$image = new Image((int)$tr[‚id_image‘]);
$path_to_image = _PS_IMG_DIR_.$params[‚image‘].’/‘.$image->getExistingImgPath().‘.‘.$this->imageType;
}else
$path_to_image = _PS_IMG_DIR_.$params[‚image‘].’/‘.$item_id.(isset($tr[‚id_image‘]) ? ‚-‚.(int)($tr[‚id_image‘]) : “).‘.‘.$this->imageType;

echo cacheImage($path_to_image, $this->table.’_mini_‘.$item_id.‘.‘.$this->imageType, 45, $this->imageType);
}
elseif (isset($params[‚icon‘]) AND (isset($params[‚icon‘][$tr[$key]]) OR isset($params[‚icon‘][‚default‘])))
echo ‚<img src=“../img/admin/‘.(isset($params[‚icon‘][$tr[$key]]) ? $params[‚icon‘][$tr[$key]] : $params[‚icon‘][‚default‘].'“ alt=“‚.$tr[$key]).'“ title=“‚.$tr[$key].'“ />‘;
elseif (isset($params[‚price‘]))
echo Tools::displayPrice($tr[$key], (isset($params[‚currency‘]) ? Currency::getCurrencyInstance((int)($tr[‚id_currency‘])) : $currency), false);
elseif (isset($params[‚float‘]))
echo rtrim(rtrim($tr[$key], ‚0‘), ‚.‘);
elseif (isset($params[‚type‘]) AND $params[‚type‘] == ‚date‘)
echo Tools::displayDate($tr[$key], (int)$cookie->id_lang);
elseif (isset($params[‚type‘]) AND $params[‚type‘] == ‚datetime‘)
echo Tools::displayDate($tr[$key], (int)$cookie->id_lang, true);
elseif (isset($tr[$key]))
{
$echo = ($key == ‚price‘ ? round($tr[$key], 2) : isset($params[‚maxlength‘]) ? Tools::substr(Tools::htmlentitiesUTF8($tr[$key]), 0, $params[‚maxlength‘]).’…‘ : Tools::htmlentitiesUTF8($tr[$key]));
echo isset($params[‚callback‘]) ? call_user_func_array(array($this->className, $params[‚callback‘]), array($echo, $tr)) : $echo;
}
else
echo ‚–‚;

echo (isset($params[‚suffix‘]) ? $params[‚suffix‘] : “).
‚</td>‘;
}

if ($this->edit OR $this->delete OR ($this->view AND $this->view !== ‚noActionColumn‘))
{
echo ‚<td style=“white-space: nowrap;“>‘;
if ($this->view)
$this->_displayViewLink($token, $id);
if ($this->edit)
$this->_displayEditLink($token, $id);
if ($this->delete AND (!isset($this->_listSkipDelete) OR !in_array($id, $this->_listSkipDelete)))
$this->_displayDeleteLink($token, $id);
if ($this->duplicate)
$this->_displayDuplicate($token, $id);
echo ‚</td>‘;
}
echo ‚</tr>‘;
}
}
}

}

?>

Vytvořte soubor CategoryController.php ve složce /override/controllers/ a zkopírujte do něj následující kod:

<?php

class CategoryController extends CategoryControllerCore {

    public function process()
    {

        $category_description = $this->category->description;
        parent::process();
        $this->category->description = $category_description;
    }

}

Update souborů šablony:
– /modules/blockcategories/category-tree-branch.tpl řádek cca 28:

<a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a> 
 

Změnit na:

<a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|strip_tags:false|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>

Dále ve složce administrace:
[složka adminu]/tabs/AdminCategories.php, řádek cca 233 s kódem:

<textarea name="description_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea> 

Změnit na:

<textarea name="description_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>

Dále v souboru [složka adminu]/tabs/AdminCategories.php, na konci (řádek cca 318) kódu:

<p class="clear"></p>';

Přidat kód pro TinyMCE:

/* Add TinyMCE */
        global $cookie;
        $iso = Language::getIsoById((int)($cookie->id_lang));
        $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
        $ad = dirname($_SERVER["PHP_SELF"]);
        echo '
            <script type="text/javascript">
            var iso = ''.$isoTinyMCE.'' ;
            var pathCSS = ''._THEME_CSS_DIR_.'' ;
            var ad = ''.$ad.'' ;
            </script>
            <script type="text/javascript" src="'.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js"></script>
            <script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce.inc.js"></script>';
        /* End TinyMCE */

 

Nakonec v /classes/Category.php, řádek cca 88:

protected     $fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isCleanHtml',
            'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');

Změnit na:

protected     $fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isString',
            'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');

Celé se to může jevit složité, ale nezabere vám to více jak pár minut.

Přikládám odkaz na eshop, kde je vidět, že to skutečně funguje: http://www.inlinekolecka.cz/5-fitness