Jump to content

Products tags on product-list.tpl


djabollo
 Share

Recommended Posts

Hi, i need to put product tags on product-list... unfortunately i can't find any module or tutorial how to get it. If anyone know how, please share the knowledge. I use presta 1.3. Best regards. Peter

Share this post


Link to post
Share on other sites

Hi Benjamin, my client wants to have all tags for every product in product-list, next to product description; clicking on the tag user will be able to get other list of product with the same tag. I'll add the search link to every tag, but i have no idea how to put tags on tpl file. I have a solution for product.tpl, but it doesn't work with product-list.tpl. Hope i explained clearly :) Sorry if my english is a little unclear.

Share this post


Link to post
Share on other sites

  • 1 month later...

Hi there, you can do this by modifying Classes > Product.php. In the function getProductProperties, before the line:

 

self::$producPropertiesCache[$cacheKey] = $row;

 

add two lines:

 

$row['tags'] = Tag::getProductTags((int)$row['id_product']);
$row['tags'] = $row['tags'][(int)$id_lang];

 

In product-list.tpl, you can read the tags as an array e.g:

 

{foreach from=$product.tags item=ptag}
{/foreach}

 

To read from product.tpl, the lookup is:

 

{foreach from=$product->tags[$lang_id] item=ptag}
{/foreach}

 

Ideally you shouldn't modify core classes and override them instead but I've found some class overrides break so for the odd line of code, I just add it to the main class and note what I've changed.

  • Like 1

Share this post


Link to post
Share on other sites

Hi there, you can do this by modifying Classes > Product.php. In the function getProductProperties, before the line:

 

self::$producPropertiesCache[$cacheKey] = $row;

 

add two lines:

 

$row['tags'] = Tag::getProductTags((int)$row['id_product']);
$row['tags'] = $row['tags'][(int)$id_lang];

 

In product-list.tpl, you can read the tags as an array e.g:

 

{foreach from=$product.tags item=ptag}
{/foreach}

 

To read from product.tpl, the lookup is:

 

{foreach from=$product->tags[$lang_id] item=ptag}
{/foreach}

 

Ideally you shouldn't modify core classes and override them instead but I've found some class overrides break so for the odd line of code, I just add it to the main class and note what I've changed.

 

 

Hello Andrew

Maybe you can help me, i need to put the "main category" of the product above the price, i´m trying edit the product.tlp file but i don't know the code.

Regards!

Share this post


Link to post
Share on other sites

Hello Andrew

Maybe you can help me, i need to put the "main category" of the product above the price, i´m trying edit the product.tlp file but i don't know the code.

Regards!

 

If you mean the direct parent category of the product, you'd use:

 

{$category->name|escape:'htmlall':'UTF-8'}

 

If you mean the root category, you can pick any out of the path. If you have a breadcrumb included (breadcrumb.tpl), you can use the $path variable or just assign it if not:

 

{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}

 

That's the full breadcrumb with links but you can extract the names by doing:

 

{assign var=pathstrip value=$path|strip_tags}
{assign var=pathname value='>'|explode:$pathstrip}
{strip}{$pathname[0]}{/strip}

Share this post


Link to post
Share on other sites

  • 5 years later...

Hi ! I use PS 1.6.1.15
I have put all product tags on category.tpl.
I added this:

<ul class="producttags">
{foreach from=$products item=product name=products}
{foreach from=Tag::getProductTags($product.id_product) key=k item=v}
{foreach from=$v item=value}
<li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
{/foreach}
{/foreach}
  {/foreach}
</ul>

 

after this part:

 

{include file="./product-list.tpl" products=$products}
<div class="content_sortPagiBar">
<div class="bottom-pagination-content clearfix">
{include file="./product-compare.tpl" paginationId='bottom'}
                    {include file="./pagination.tpl" paginationId='bottom'}
</div>
</div>
 
 
 
 
you can add this styles to the global.css located in themes>default-bootstrap>css:
 
  1. .producttags {
  2.     list-style:none;
  3.     position:relative;
  4.     clear:both;
  5.     display:block;
  6.     padding-bottom:20px;
  7.     margin-bottom:20px;
  8. }
  9.  
  10. .producttags li, .producttags a{
  11.     float:left;
  12.     height:24px;
  13.     line-height:24px;
  14.     position:relative;
  15.     font-size:11px;
  16.     margin-bottom: 5px;
  17.     }
  18.  
  19. .producttags a{
  20.     margin-left:20px;
  21.     padding:0 10px 0 12px;
  22.     background:#0089e0;
  23.     color:#fff;
  24.     text-decoration:none;
  25.     -moz-border-radius-bottomright:4px;
  26.     -webkit-border-bottom-right-radius:4px;
  27.     border-bottom-right-radius:4px;
  28.     -moz-border-radius-topright:4px;
  29.     -webkit-border-top-right-radius:4px;    
  30.     border-top-right-radius:4px;    
  31. }
  32. .producttags a:visited{
  33.     color:#fff;
  34. }
  35.  
  36. .producttags a:before{
  37.     content:"";
  38.     float:left;
  39.     position:absolute;
  40.     top:0;
  41.     left:-12px;
  42.     width:0;
  43.     height:0;
  44.     border-color:transparent #0089e0 transparent transparent;
  45.     border-style:solid;
  46.     border-width:12px 12px 12px 0;      
  47. }
  48.  
  49. .producttags a:after{
  50.     content:"";
  51.     position:absolute;
  52.     top:10px;
  53.     left:0;
  54.     float:left;
  55.     width:4px;
  56.     height:4px;
  57.     -moz-border-radius:2px;
  58.     -webkit-border-radius:2px;
  59.     border-radius:2px;
  60.     background:#fff;
  61.     -moz-box-shadow:-1px -1px 2px #004977;
  62.     -webkit-box-shadow:-1px -1px 2px #004977;
  63.     box-shadow:-1px -1px 2px #004977;
  64. }
  65.  
  66. .producttags a:hover{background:#555; text-decoration:none;}    
  67.  
  68. .producttags a:hover:before{border-color:transparent #555 transparent transparent;}

 

 

With much help from:

https://mypresta.eu/en/art/

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

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