cedced Posted June 10, 2014 Posted June 10, 2014 Bonjour, J’ai un module qui a été réalisé pour lister les attributs dans un système de recherche et je cherche la possibilité d’afficher leur traduction selon la langue choisi sur le site. Voici le code dans le fichier php du module qui cherche les valeurs : public function hookTop($params) { $attributes = $this->getCache('attributes'); $maxprice = $this->getCache('maxprice'); $this->smarty->assign(array( 'the_dances' => $attributes['dance'], 'the_publics' => $attributes['public'], 'the_places' => $attributes['place'], 'the_counties' => json_encode(array( 32 => $attributes[32], //france 33 => $attributes[33],//italia 34 => $attributes[34],//spain 36 => $attributes[36],//germany 37 => $attributes[37])),//uk 'the_maxprice' => round($maxprice['maxprice']))); return $this->display(__FILE__, 'file.tpl'); } D’abord, ai-je raison de regarder à modifier le code dans cette partie ? Ensuite, est-ce que quelqu’un aurait une solution à proposer ? Merci Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted June 10, 2014 Posted June 10, 2014 Bonjour, il faudrait connaitre le code source de la fonction getCache() utilisé dans : $attributes = $this->getCache('attributes'); Share this post Link to post Share on other sites More sharing options...
cedced Posted June 10, 2014 Posted June 10, 2014 Voila : public function getCache($filename) { return json_decode(file_get_contents(dirname(__FILE__).'/cache/'.$filename.'.json'), true); } Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted June 10, 2014 Posted June 10, 2014 ouep ben pas mieux cela n'aide pas il faudrait tout le code du module mais bon, peut être que le développeur de ce module peut le rendre multi lingue car de base cela devrait être le cas. Share this post Link to post Share on other sites More sharing options...
cedced Posted June 10, 2014 Posted June 10, 2014 Je crois que vous m'avez mis sur une bonne piste. Voici un extrait du fichier attributes.json: {"dance":[{"id_attribute":"4","id_attribute_group":"1","color":"","position":"0","id_shop":"1","id_lang":"5","name":"Africaine"} Il faut donc voir pour mettre quelque chose de dynamique avec id_lang. Share this post Link to post Share on other sites More sharing options...
cedced Posted June 10, 2014 Posted June 10, 2014 En fait ce n'est pas exactement dans ce fichier car il est cree de facon dynamique. Il y aurait plus quelque chose a faire par la : foreach($attributes as $name => $id) { $cache[$name] = AttributeGroup::getAttributes($this->context->language->id, $id); } return $this->setCache('attributes', $cache); Mais si vous voulez, pour peut-etre facilite les choses, voici le code complet de la page : if (!defined('_PS_VERSION_')) exit; class Bdwsearch extends Module { public function __construct() { $this->name = 'bdwsearch'; $this->tab = 'search_filter'; $this->version = 1.0; $this->author = 'iBroStudio'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Bdanceworld Search'); $this->description = $this->l('Bdanceworld Search sytem.'); } public function install() { if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('header') || !$this->registerHook('actionProductSave') || !$this->registerHook('actionProductUpdate') || !$this->registerHook('actionProductDelete') || !$this->registerHook('actionAttributeSave') || !$this->registerHook('actionAttributeDelete') || !$this->setMaxPriceCache() || !$this->setAttributesCache()) return false; return true; } public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'bdwsearch.css', 'all'); } public function hookTop($params) { $attributes = $this->getCache('attributes'); $maxprice = $this->getCache('maxprice'); $this->smarty->assign(array( 'bdw_dances' => $attributes['dance'], 'bdw_publics' => $attributes['public'], 'bdw_places' => $attributes['place'], 'bdw_counties' => json_encode(array( 32 => $attributes[32], //france 33 => $attributes[33],//italia 34 => $attributes[34],//spain 36 => $attributes[36],//germany 37 => $attributes[37],//uk 38 => $attributes[38],//domtom 39 => $attributes[39],//swiss 40 => $attributes[40])),//belgium 'bdw_products' => $attributes['products'], 'bdw_colors' => $attributes['color'], 'bdw_activities' => $attributes['activity'], 'bdw_maxprice' => round($maxprice['maxprice']))); return $this->display(__FILE__, 'bdwsearch.tpl'); } public function hookActionProductSave($params) { $this->setAttributesCache(); $this->setMaxPriceCache(); } public function hookActionProductUpdate($params) { $this->hookActionProductSave($params); } public function hookActionProductDelete($params) { $this->hookActionProductSave($params); } public function hookActionAttributeSave($params) { $this->setAttributesCache(); } public function hookActionAttributeDelete($params) { $this->hookActionAttributeSave($params); } protected function setMaxPriceCache() { $max_price = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT MAX(price) as maxprice FROM '._DB_PREFIX_.'product WHERE active = 1'); return $this->setCache('maxprice', $max_price); } protected function setAttributesCache() { $cache = array(); $attributes = array( 'dance' => 1, 'public' => 8, 'place' => 3, 'products' => 2, 'activity' => 5, 'color' => 6, 'size' => 7, 'belt' => 18, 'bra' => 17, 'skirt' => 19, 32 => 9, //france 33 => 12,//italia 34 => 13,//spain 36 => 15,//germany 37 => 16,//uk 38 => 10,//domtom 39 => 11,//swiss 40 => 14);//belgium foreach($attributes as $name => $id) { $cache[$name] = AttributeGroup::getAttributes($this->context->language->id, $id); } return $this->setCache('attributes', $cache); } protected function setCache($filename, $data) { return file_put_contents(dirname(__FILE__).'/cache/'.$filename.'.json', json_encode($data)); } public function getCache($filename) { return json_decode(file_get_contents(dirname(__FILE__).'/cache/'.$filename.'.json'), true); } } Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now