1

有人可以告诉我如何在 prestashop 1.6 的 TopColumn 中显示标签吗?我知道我必须编辑 blogtags.php 但我不知道该怎么做——我的 PHP 太弱了。

当然我试过了——现在我可以在管理面板中挂钩标签,但不能在网站上挂钩。我做了什么?

.
.
.
function install()
    {
        $success = (parent::install() && $this->registerHook('header') && **$this->registerHook('displayTopColumn')** && Configuration::updateValue('BLOCKTAGS_NBR', 10));

        if ($success)
.
.
.
public function hookdisplayTop($params)
    {
        return $this->hookdisplayTopColumn($params);
    }
.
.
.

完整的 blogtags.php

if (!defined('_PS_VERSION_'))
    exit;

define('BLOCKTAGS_MAX_LEVEL', 3);

class BlockTags extends Module
{
    function __construct()
    {
        $this->name = 'blocktags';
        $this->tab = 'front_office_features';
        $this->version = '1.2.1';
        $this->author = 'PrestaShop';
        $this->need_instance = 0;

        $this->bootstrap = true;
        parent::__construct();  

        $this->displayName = $this->l('Tags block');
        $this->description = $this->l('Adds a block containing your product tags.');
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    }

    function install()
    {
        $success = (parent::install() && $this->registerHook('header') && $this->registerHook('displayTopColumn') && Configuration::updateValue('BLOCKTAGS_NBR', 10));

        if ($success)
        {
            // Hook the module either on the left or right column
            $theme = new Theme(Context::getContext()->shop->id_theme);
            if ((!$theme->default_left_column || !$this->registerHook('leftColumn'))
                && (!$theme->default_right_column || !$this->registerHook('rightColumn'))
                && $this->registerHook('displayTopColumn'))
            {
                // If there are no colums implemented by the template, throw an error and uninstall the module
                $this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one');
                parent::uninstall();
                return false;
            }
        }
        return $success;
    }

    public function getContent()
    {
        $output = '';
        if (Tools::isSubmit('submitBlockTags'))
        {
            if (!($tagsNbr = Tools::getValue('BLOCKTAGS_NBR')) || empty($tagsNbr))
                $output .= $this->displayError($this->l('Please complete the "Displayed tags" field.'));
            elseif ((int)($tagsNbr) == 0)
                $output .= $this->displayError($this->l('Invalid number.'));
            else
            {
                Configuration::updateValue('BLOCKTAGS_NBR', (int)$tagsNbr);
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }
        return $output.$this->renderForm();
    }

    /**
    * Returns module content for left column
    *
    * @param array $params Parameters
    * @return string Content
    *
    */
    function hookLeftColumn($params)
    {
        $tags = Tag::getMainTags((int)($params['cookie']->id_lang), (int)(Configuration::get('BLOCKTAGS_NBR')));

        $max = -1;
        $min = -1;
        foreach ($tags as $tag)
        {
            if ($tag['times'] > $max)
                $max = $tag['times'];
            if ($tag['times'] < $min || $min == -1)
                $min = $tag['times'];
        }

        if ($min == $max)
            $coef = $max;
        else
        {
            $coef = (BLOCKTAGS_MAX_LEVEL - 1) / ($max - $min);
        }

        if (!sizeof($tags))
            return false;
        foreach ($tags AS &$tag)
            $tag['class'] = 'tag_level'.(int)(($tag['times'] - $min) * $coef + 1);
        $this->smarty->assign('tags', $tags);

        return $this->display(__FILE__, 'blocktags.tpl');
    }

    function hookRightColumn($params)
    {
        return $this->hookLeftColumn($params);
    }

    function hookHeader($params)
    {
        $this->context->controller->addCSS(($this->_path).'blocktags.css', 'all');
    }
    public function hookdisplayTop($params)
    {
        return $this->hookdisplayTopColumn($params);
    }
    public function renderForm()
    {
        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Settings'),
                    'icon' => 'icon-cogs'
                ),
                'input' => array(
                    array(
                        'type' => 'text',
                        'label' => $this->l('Displayed tags'),
                        'name' => 'BLOCKTAGS_NBR',
                        'class' => 'fixed-width-xs',
                        'desc' => $this->l('Set the number of tags you would like to see displayed in this block.')
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                )
            ),
        );

        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->table =  $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitBlockTags';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFieldsValues(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );

        return $helper->generateForm(array($fields_form));
    }

    public function getConfigFieldsValues()
    {       
        return array(
            'BLOCKTAGS_NBR' => Tools::getValue('BLOCKTAGS_NBR', Configuration::get('BLOCKTAGS_NBR')),
        );
    }

}
4

1 回答 1

2

改变这个:

public function hookdisplayTop($params)
{
    return $this->hookdisplayTopColumn($params);
}

对此:

public function hookdisplayTopColumn($params)
{
    return $this->hookLeftColumn($params);
}
于 2014-07-17T21:52:51.237 回答