Jump to content

Modifier le module Homefeatured


Recommended Posts

Bonjour,

Je souhaiterais dupliquer le module homefeatured afin de le placer dans les pages de catégories. Cependant je souhaite qu'il ne m'affiche que les promotions.

Je sais dupliquer le module et le mettre dans les pages de catégories. Mais voilà je ne sais pas comment modifier le code pour que ce dernier ne m'affiche que les promotions de la catégorie courante.

Une âme charitable pourrait-elle m'indiquer comment modifier le fichier homefeatured.php pour faire cela svp ?

<?php

class HomeFeatured extends Module
{
   private $_html = '';
   private $_postErrors = array();

   function __construct()
   {
       $this->name = 'homefeatured';
       $this->tab = 'Tools';
       $this->version = '0.9';

       parent::__construct();

       $this->displayName = $this->l('Featured Products on the homepage');
       $this->description = $this->l('Displays Featured Products in the middle of your homepage');
   }

   function install()
   {
       if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) OR !parent::install() OR !$this->registerHook('home'))
           return false;
       return true;
   }

   public function getContent()
   {
       $output = ''.$this->displayName.'';
       if (Tools::isSubmit('submitHomeFeatured'))
       {
           $nbr = intval(Tools::getValue('nbr'));
           if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
               $errors[] = $this->l('Invalid number of product');
           else
               Configuration::updateValue('HOME_FEATURED_NBR', $nbr);
           if (isset($errors) AND sizeof($errors))
               $output .= $this->displayError(implode('
', $errors));
           else
               $output .= $this->displayConfirmation($this->l('Settings updated'));
       }
       return $output.$this->displayForm();
   }

   public function displayForm()
   {
       $output = '
       <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'

'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'

'.$this->l('Number of product displayed').'

                   <input type="text" size="5" name="nbr" value="'.Tools::getValue('nbr', Configuration::get('HOME_FEATURED_NBR')).'" />

'.$this->l('The number of products displayed on homepage (default: 10)').'


<input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" />

       </form>';
       return $output;
   }

   function hookHome($params)
   {
       global $smarty;
       $category = new Category(1);
       $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
       $products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
       $smarty->assign(array(
           'allow_buy_when_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK', false),
           'max_quantity_to_allow_display' => Configuration::get('PS_LAST_QTIES'),
           'category' => $category,
           'products' => $products,
           'currency' => new Currency(intval($params['cart']->id_currency)),
           'lang' => Language::getIsoById(intval($params['cookie']->id_lang)),
           'productNumber' => sizeof($products),
           'homeSize' => Image::getSize('home')
       ));
       return $this->display(__FILE__, 'homefeatured.tpl');
   }

}



Merci :)

Link to comment
Share on other sites

J'essaie et j'essaie encore mais rien à faire ...

Je pense que la partie à modifier est la suivante :

function hookHome($params)
   {
       global $smarty;
       $category = new Category(1);
       $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
       $products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
       $smarty->assign(array(
           'allow_buy_when_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK', false),
           'max_quantity_to_allow_display' => Configuration::get('PS_LAST_QTIES'),
           'category' => $category,
           'products' => $products,
           'currency' => new Currency(intval($params['cart']->id_currency)),
           'lang' => Language::getIsoById(intval($params['cookie']->id_lang)),
           'productNumber' => sizeof($products),
           'homeSize' => Image::getSize('home')
       ));
       return $this->display(__FILE__, 'homefeatured.tpl');
   }



La variable récupérant l'id de la catégorie est $category
Par conséquent, sachant que pour récupérer l'id d'une page il faut faire : $smarty.get.id_category (vu sur un autre post),
il me paraît donc logique de remplacer :

$category = new Category(1);



Par :

$category =  $smarty.get.id_category;



Hors cela ne fonctionne pas du tout ... :/
Mes compétences en dev sont plutôt très très faible... [mod honte ON]

Si seulement c'était aussi simple ... :/

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...