2014-07-17 1 views
1

Quelqu'un peut-il me dire comment afficher les tags dans TopColumn dans prestashop 1.6? Je sais que je dois éditer blogtags.php mais je ne sais pas comment le faire - mon PHP est trop faible.Comment accrocher des tags à displayTopColumn dans prestashop 1.6

Bien sûr, j'ai essayé - maintenant je peux accrocher la balise dans le panneau d'administration, mais pas sur le site Web. Qu'est-ce que j'ai fait?

. 
. 
. 
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 pleine

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')), 
     ); 
    } 

} 

Répondre

2

Modifier ceci:

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

Pour que:

public function hookdisplayTopColumn($params) 
{ 
    return $this->hookLeftColumn($params); 
} 
Questions connexes