Jump to content

Résolu - Afficher catégorie soeur page produit ps 1.6


Recommended Posts

Bonjour,

je voudrais afficher les sœurs de la catégorie par défaut de mon produit sur la page produit.

Pourriez-vous me dire comment m'y prendre ?

J'ai testé avec ça, mais ça ne renvoi rien

<ul>
{foreach Category::getChildren($product->id_category_default, 1) as $category}
<li><a href="{$link->getCategoryLink($category.id_category)}">{$category.name}</a></li>
{/foreach}
</ul>

Merci pour votre aide.

Je suis sous ps 1.6

Edited by Manu-shop (see edit history)

Share this post


Link to post
Share on other sites

Just now, doekia said:

Vous dites chercher les soeurs mais votre code cherche les enfants (filles)

Oui, d'où ma demande. Je ne trouve pas comment afficher les sœurs, une info ?

Merci pour votre aide précieuse

Share this post


Link to post
Share on other sites

Non testé

{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_default_category}
  ORDER BY c2.nleft
{/capture}
<ul>
{foreach Db::getInstance()->executeS($smarty.capture.sql) as $category_siblings}
   {if $category_siblings.id_category != $product->id_default_category}
  <li> .... </li>
   {/if}
{/foreach}
</ul>

 

Share this post


Link to post
Share on other sites

10 minutes ago, doekia said:
{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_default_category}
  ORDER BY c2.nleft
{/capture}

Pour un fichier php, product.php?

Share this post


Link to post
Share on other sites

{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_category_default|intval}
  ORDER BY c2.nleft
{/capture}
<ul>
{foreach Db::getInstance()->executeS($smarty.capture.sql) as $category_siblings}
   {if $category_siblings.id_category != $product->id_category_default}
  <li> .... </li>
   {/if}
{/foreach}
</ul>

Testé et fonctionelle

Share this post


Link to post
Share on other sites

14 minutes ago, doekia said:
{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_category_default|intval}
  ORDER BY c2.nleft
{/capture}
<ul>
{foreach Db::getInstance()->executeS($smarty.capture.sql) as $category_siblings}
   {if $category_siblings.id_category != $product->id_category_default}
  <li> .... </li>
   {/if}
{/foreach}
</ul>

Testé et fonctionelle

Y a du mieux, ça m'affiche uniquement les ... les li dans les product.tpl

Share this post


Link to post
Share on other sites

5 hours ago, doekia said:
{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_category_default|intval}
  ORDER BY c2.nleft
{/capture}
<ul>
{foreach Db::getInstance()->executeS($smarty.capture.sql) as $category_siblings}
   {if $category_siblings.id_category != $product->id_category_default}
  <li> .... </li>
   {/if}
{/foreach}
</ul>

Testé et fonctionelle

Ca avance, les ID de catégories s'affichent bien. Comment afficher le mon de ces catégories avec l'id?

	{capture name="sql"}
  SELECT c2.id_category
  FROM `{$smarty.const._DB_PREFIX_}category` c
  INNER JOIN `{$smarty.const._DB_PREFIX_}category` c2 ON c2.id_parent = c.id_parent
  WHERE c.id_category = {$product->id_category_default|intval}
  ORDER BY c2.nleft
{/capture}
<ul>
{foreach Db::getInstance()->executeS($smarty.capture.sql) as $category_siblings}
   {if $category_siblings.id_category != $product->id_category_default}
  <li> <a href="{$link->getCategoryLink($category_siblings.id_category)}">???</a> </li>
   {/if}
{/foreach}
</ul>

 

Edited by Manu-shop (see edit history)

Share this post


Link to post
Share on other sites

Pour afficher le nom de la catégorie, j'ai essayé ca:

<a href="{$link->getCategoryLink($category_siblings.id_category)}">{$category_siblings.id_category}{$category_siblings->name}</a>
  <a href="{$link->getCategoryLink($category_siblings.id_category, $category_siblings.link_rewrite)}">{$category_siblings.name}</a>

Mais aucun ne fonctionne.

Une idée ?

Share this post


Link to post
Share on other sites

  • Manu-41 changed the title to Afficher catégorie soeur page produit ps 1.6
1 hour ago, doekia said:

soit:

  1. ajouter une jointure sur category_lang et reprendre le champ name
  2. utiliser Category::getCategoryInformations((array)category_sibling.id_category

J’ai utilisé FrontController::getCategoryName

Ça fonctionne.

Merci encore pour ton aide 😉

Share this post


Link to post
Share on other sites

  • Manu-41 changed the title to Résolu - Afficher catégorie soeur page produit ps 1.6

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More