Jump to content

problème de pagination après modification du product-list.tpl


Recommended Posts

Bonjour,

 

Je me suis inspiré de ce post http://www.prestashop.com/forums/topic/106880-astuce-afficher-la-liste-des-couleurs-dans-la-liste-des-produits-survol/page__st__20 pour modifier mon product-list.tpl qui me permet d'afficher toutes mes variantes de produits (par exemple, je liste l'ipod nano et j'ai une ligne pour le bleu, une ligne pour le vert, etc...)

 

Pour ce faire, j'ai surchargé le controller CategoryController.php

 

public function productListAssign()
{
 $hookExecuted = false;
 Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
 if(!$hookExecuted) // The hook was not executed, standard working
 {
  self::$smarty->assign('categoryNameComplement', '');
  $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
  $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);
  foreach ($this->cat_products as $key => $cat_product) {
   $product = new Product(intval($cat_product['id_product']), true, intval(self::$cookie->id_lang));
   $colors = array();
   $attributesGroups = Db::getInstance()->ExecuteS('
   SELECT pai.`id_image`, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
   a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, pa.`minimal_quantity`
   FROM `'._DB_PREFIX_.'product_attribute` pa
   LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
   LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON pai.`id_product_attribute` = pa.`id_product_attribute`
   LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
   LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
   LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
   LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
   WHERE pa.`id_product` =  '.(int)($product->id).'
   AND al.`id_lang` =  '.self::$cookie->id_lang.'
   AND agl.`id_lang` = '.self::$cookie->id_lang.'
   AND ag.`is_color_group` = 1
   GROUP BY attribute_name
   ORDER BY agl.`public_name`, al.`name`');
   if (Db::getInstance()->numRows())
   {
    foreach ($attributesGroups AS $k => $row)
    {
	    /* Color management */
	    if (isset($row['attribute_color']) AND $row['attribute_color'] AND $row['id_attribute_group'] == $product->id_color_default)
	    {
		    $colors[$row['id_attribute']]['value'] = $row['attribute_color'];
		    $colors[$row['id_attribute']]['name']  = $row['attribute_name'];
		    $colors[$row['id_attribute']]['id_image']  =(($row['id_image'] != NULL) ? intval($row['id_image']) : -1);
	    }
    }
   }
   $this->cat_products[$key]['colors'] = $colors;
  }
 }
 else // Hook executed, use the override
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
 self::$smarty->assign('nb_products', (int)$this->nbProducts);
}

 

J'ai aussi modifier le product-list.tpl pour l'affichage.

 

Mais je rencontre maintenant un souci au niveau de la pagination. lorsque je liste tous mes produits, la pagination me compte le nombre de produit sans compter les couleurs plutôt que me compter les variante (par exemple, si j'affiche un ipod nano avec 5 couleurs -donc une liste de 5 produits sur la page-, ca ne me compte qu'1 produit au lieu de 5).

 

Je cherche à le modifier mais j'ai du mal à trouver. merci pour votre aide :)

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