Jump to content

Création d'un module dans la même marque


Recommended Posts

Bonjour,

Je cherche à faire un module similaire à productscategory, mais pour les fabricants (suppliers). J'ai donc fait une copie de productscategory, tout renommé en productssupplier. J'ai rajouté le module dans la base de données, et le module apparaît bien dans la liste de mes modules.

Par contre dans le front, rien n'apparaît. Si je fais un die('test') dans la méthode hook de productscategory, ca marche, par contre si je fais la même chose dans mon productssupplier, pas de die, il n'a pas l'air d'exécuter le code.

mes questions :

- est ce que j'ai des modifs à faire pour qu'il prenne en compte mon hook ?

- y'a t il un moyen de débugger la création de modules ?

<?php

class productsSupplier extends Module
{
    function __construct()
    {
         $this->name = 'productssupplier';
         $this->version = '1.0';
         $this->tab = 'Products';

       parent::__construct();
       $this->page = basename(__FILE__, '.php');
       $this->displayName = $this->l('Products Supplier');
       $this->description = $this->l('Display products of the same supplier on the product page');
    }

   function install()
   {
        if (!parent::install()){
            return false;
       } 

       if (!$this->registerHook('productfooter'))
           return false;
       return true;
   }

   private function getCurrentProduct($products, $id_current)
   {
       if ($products)
           foreach ($products as $key => $product)
               if ($product['id_product'] == $id_current)
                   return $key;
       return false;
   }

   public function hookProductFooter($params)
   {
       global $smarty, $cookie;
       die('test');

       $idProduct = intval(Tools::getValue('id_product'));
       $product = new Product(intval($idProduct));

       echo '<!-- hook footer : ';
       var_dump($product);
       echo '-->';

       $category = new Category(1);

       if (isset($params['category']->id_category))
           $category = $params['category'];
       if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
           $category = New Category(intval($product->id_category_default));
       if (!Validate::isLoadedObject($category))
           Tools::displayError('Bad category !');

       // Get infos
       $sizeOfCategoryProducts = $category->getProducts(intval($cookie->id_lang), 1, 30, NULL, NULL, true);
       $categoryProducts = $category->getProducts(intval($cookie->id_lang), 1, $sizeOfCategoryProducts);

       // Get positions
       $middlePosition = round($sizeOfCategoryProducts / 2, 0);
       $productPosition = $this->getCurrentProduct($categoryProducts, $idProduct);

       // Flip middle product with current product
       if ($productPosition)
       {
           $tmp = $categoryProducts[$middlePosition-1];
           $categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
           $categoryProducts[$productPosition] = $tmp;
       }

       // If products tab higher than 30, slice it
       if ($sizeOfCategoryProducts > 30)
       {
           $categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
           $middlePosition = 15;
       }

       // Display tpl
       $smarty->assign('categoryProducts', $categoryProducts);
       $smarty->assign('middlePosition', $middlePosition);
       return $this->display(__FILE__, 'productscategory.tpl');
   }
}
?>



merci,

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