Jump to content

Récupérer images catégories


Recommended Posts

Bonjour,

 

Je suis nouveau sur prestashop et je trouve ce cms très complet !!

 

J'essaie de modifier le module homefeatured pour qu'il affiche les catégorie sur la page d'accueil. Tout fonctionne mis à part l'affichage des images.... Voici le code que j'ai pondu :

 

{foreach from=$blockCategTree.children item=child name=homeFeaturedProducts}
  <li>
{if $child.link == "http://www.colorexpress.ch/prestashop/category.php?id_category=13"}
<a class="product_image" href="http://www.colorexpress.ch/prestashop/cms.php?id_cms=15" title="{$child.name|escape:html:'UTF-8'}">
{else}
<a class="product_image" href="{$child.link}" title="{$child.name|escape:html:'UTF-8'}">
{/if}

{if $child.id_image} <!-- ne trouve pas d'image.....-->
 <img src="{$link->getCatImageLink($child->link_rewrite, $child->id_image, 'small')}" alt="{$child.name|escape:html:'UTF-8'}" />
{else}
 pas d'image
{/if}
</a>

{if $child.link == "http://www.colorexpress.ch/prestashop/category.php?id_category=13"}
<a class="button_small" href="http://www.colorexpress.ch/prestashop/cms.php?id_cms=15" title="{l s='View' mod='homefeatured'}">{$child.name|escape:html:'UTF-8'}</a>
{else}
<a class="button_small" href="{$child.link}" title="{l s='View' mod='homefeatured'}">{$child.name|escape:html:'UTF-8'}</a>
{/if}
  </li>
  {/foreach}

 

 

C'est comme s'il n y avait pas d'images dans mes catégories alors qu'il y en a bien.

 

J'ai entendu dire que c'était un bug connu ?

 

Ma version de prestashop est : PrestaShop™ 1.4.7.0

 

Le lien : http://www.colorexpress.ch/prestashop/

Link to comment
Share on other sites

Dans le fichier où tu a mis le code (category.tpl ?) tu mets en début de fichier {debug}

 

Quand tu chargeras ta page, ça t'affichera une pop-up listant l'ensemble de toutes les variables smarty chargées avec cette page.

Tu pourras donc notamment voir ce que contient la variable $blockCategTree.children

Link to comment
Share on other sites

J'ai ajouté {debug} a mon fichier et apparemment les images ne font pas parti des variables. Par contre, j'ai remarqué que quand on ajoute une image à une catégorie, l'image prend comme nom le numéro de la catégorie (si celui-là est disponible). Du coup, j'ai modifié mon code comme cela et ça fonctionne :

 

{foreach from=$blockCategTree.children item=child name=homeFeaturedProducts}
  <li>
   {if $child.link == "http://www.colorexpress.ch/prestashop/category.php?id_category=13"}
   <a class="product_image" href="http://www.colorexpress.ch/prestashop/cms.php?id_cms=15" title="{$child.name|escape:html:'UTF-8'}">
   {else}
   <a class="product_image" href="{$child.link}" title="{$child.name|escape:html:'UTF-8'}">
   {/if}
 [b]<img src="/prestashop/img/c/{$child.id}-medium.jpg" alt="{$child.name|escape:html:'UTF-8'}" />[/b]
   </a>

   {if $child.link == "http://www.colorexpress.ch/prestashop/category.php?id_category=13"}
   <a class="button_small" href="http://www.colorexpress.ch/prestashop/cms.php?id_cms=15" title="{l s='View' mod='homefeatured'}">{$child.name|escape:html:'UTF-8'}</a>
   {else}
   <a class="button_small" href="{$child.link}" title="{l s='View' mod='homefeatured'}">{$child.name|escape:html:'UTF-8'}</a>
   {/if}
  </li>
  {/foreach}

 

Ceci est biensûr une solution temporaire. Elle fonctionne tant qu'on ne remplace pas les images. Si on veut modifier une image, il faut d'abord la supprimer du FTP pour que la nouvelle puisse prendre le nom de l'ancienne.

Link to comment
Share on other sites

Pourquoi tu mets :

{$link->getCatImageLink($child.link_rewrite, $child.id_image, 'small')}

 

La méthode getCatImageLink demande les attributs suivants:

getCatImageLink($name, $id_category, $type = null)

 

Donc pourquoi pas simplement:

{$link->getCatImageLink($category->link_rewrite, $child.id, 'small')}

Car la fonction demande l'id de la catégorie, pas l'id image.

 

Le link_rewrite lui est dans la variable $category (à essayer avec un . si la -> ne marche pas).

 

EDIT: la variable category ne se trouve pas dans la page d'accueil donc essaies peut être simplement avec $child.link mais je doute que ça marche.

 

RE-EDIT: bon ben si ça marche ! :rolleyes:

Edited by franckm1000 (see edit history)
  • Like 1
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...