Jump to content

features or tags on ProductList


Recommended Posts

Hi there, i don't know if i posted in the right category but here it is.

I want to have the product features or the tags in the ProductList after the description.

So. Lets say i have the Iphone as a product. I want to have his features under the description

like: Wifi, Touchscreen, Bluetooth, etc...

In the attachament i put some icons, simbolic to the features.. because i want to make something like

feature_name a>


or
tag1, tag2, tag3,

11392_tGUH3pmdeRZ0GRL5WAMR_t

Share this post


Link to post
Share on other sites

in product.php get the feature list or tag list from tables:product_tag, feature_product


in themes/yourtheme/product-list.tpl you can display them

Share this post


Link to post
Share on other sites

merci radu.

Can you please help me a little bit... i can't pull it off.
i get he error hack attempt when i play in Category.php (from classes)

Can you please tell me what line should i edit, thx

(salutari din bucuresti/greetings from bucharest)

Share this post


Link to post
Share on other sites

I've needed only one tag in product listing page - but you can manage to get them all - there are more posibilities.

in Category class the new query (the latest added tag):

        $sql = '
       SELECT p.*, tg.name as tag_name, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
                   (p.price - IF((DATEDIFF(reduction_from, CURDATE()) <= 0 AND DATEDIFF(reduction_to, CURDATE()) >=0) OR reduction_from = reduction_to, IFNULL(reduction_price, (p.price * reduction_percent / 100)),0)) AS orderprice 
       FROM `'._DB_PREFIX_.'category_product` cp
       LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
       LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
       LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
       LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
       LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`        
       LEFT JOIN `'._DB_PREFIX_.'tag` tg ON (tg.id_lang='.intval($id_lang).' AND tg.id_tag=(SELECT id_tag FROM product_tag WHERE id_product=p.id_product ORDER BY id_tag DESC LIMIT 1))
       WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'
       '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '');




in product-list.tpl from themes I've used:

{$product.tag_name}






---------------------------------------------------------------------------------------------------------
However in your case you need all the features/tags (i think it's better using tags because you only need to place some images - there is no need for features that have name/value)

so you can use for each product Tag::getProductTags($product_id); to get all product tags after this line in category.php

$cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);

Share this post


Link to post
Share on other sites
  • 4 weeks later...

I am trying to do a similar thing. I need my feature (Size) to be displayed in the product listing. I modified the product.tpl to move the feature from the data sheet up to right below the short desc. I then tried copying that bit of code:

>
</pre>
<ul>
       {foreach from=$features item=feature}
{$feature.name|escape:'htmlall':'UTF-8'} {$feature.value|escape:'htmlall':'UTF-8'}
       {/foreach} 
</ul>



But it does not display anything.

Reading the above it would seem I need to add something to classes/Products.php, but it is not clear from the above what exactly I have to add.

Also is there a way to get the manufacturer to display right below the Feature on both the product info page and the product listing page? I could not seem to find the variable to include.

Any help would be appreciated.

thanks

Share this post


Link to post
Share on other sites
  • 1 month later...

HI

Thanks a lot for your reply. I would like to display tags in product list, please look through attached screen shot.
I have modified query in category.php class file but unable to display tags info. Please someone could help me on this

13895_BFDkprJoYiqiPVrk9Xj4_t

Share this post


Link to post
Share on other sites

This is my code in product.tpl to show the tags when viewing the product:

   {if $product->tags}
{l s='Tags'}:
           {foreach from=$product->tags item=tag1}
           {foreach from=$tag1 item=author}
{$author}
           {/foreach}
           {/foreach}

   {/if}


Maybe entering that or something similar in product-list.tpl will do the trick?

/Mats

Share this post


Link to post
Share on other sites

I took a look in the code and the expected (by me) $product.tags doesn't contain the tags, so I don't know...
Is there a way to find out what eg $product contains, for me a not too experienced nor skilled programmer (if I can call me that at all) it would be a great help.

/Mats

Share this post


Link to post
Share on other sites

I would use the following code in the PHP file just before assigning the variables to the template:

echo var_dump($products);



The output is plain text and doesn't display well in the browser though. It is best to view the source of the code so you can see the line breaks.

Share this post


Link to post
Share on other sites

I keep losing track when looking through the code. :-( A bit similar feeling as when I try to figure out how to show the tags for just one language (in product.tpl)...
I found that in product-list.tpl, $tags holds all the tags (for all products) so maybe one way is to filter out the correct tags from that array. Don't know how to do that though.

/Mats

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 9 months later...

Hi All,

What I made here is to add the array of tags in the list of properties of the product.

To do that go to classes/Product.php, and within the getProductProperties function you should include the following line where the data is stored, about line 2200:

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



Then all you need to do is to include the following loop of tags into the product-list.tpl:


{if $product.tags}
   {foreach from=$product.tags item=tag1}
   {foreach from=$tag1 item=tag}

      
{$tag|escape:'htmlall':'UTF-8'}                       

   {/foreach}
   {/foreach}
{/if}



Hope this helps... :D

Share this post


Link to post
Share on other sites
  • 1 month later...

Thanks lafondadebaco

This is starting to make sense.
Would you be kind enough to translate this to features rather than tags?
I'd like to display features in my product lists.

That's one thing.

The other thing is, could you help me isolate just one of the four features?
the foreach list them all, how can I access just one of them?

Thanks in advance.
Nik

Share this post


Link to post
Share on other sites

What I did for feature(s):
Look in the DB in ps_feature_lang for the id_feature of the wanted feature, in my case 8 - "Suggested Rank".
Go to the getNewProducts function in classes/product.php and alter the code into something like this

$result = Db::getInstance()->ExecuteS('
SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, rk.`value`
AS rank, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'feature_product` r ON (r.`id_product` = p.`id_product` AND r.`id_feature` = 8)
LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` rk ON (rk.`id_feature_value` = r.`id_feature_value` AND rk.`id_lang` = '.intval($id_lang).')
WHERE p.`active` = 1


(r, rk, rank, id_feature, id_lang, and possibly more are keywords to look for to find my changes to the original code)

Then I use the following in themes/product-list.php

{if $product.rank} 
{l s='Rank'}: {$product.rank} {/if}



/Mats
PS Sorry for not explaining this better, I got lots of help with this and don't fully understand it myself

Share this post


Link to post
Share on other sites
  • 3 weeks later...
  • 3 months later...
Hi All,

What I made here is to add the array of tags in the list of properties of the product.

To do that go to classes/Product.php, and within the getProductProperties function you should include the following line where the data is stored, about line 2200:

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



Then all you need to do is to include the following loop of tags into the product-list.tpl:


{if $product.tags}
   {foreach from=$product.tags item=tag1}
   {foreach from=$tag1 item=tag}

      
{$tag|escape:'htmlall':'UTF-8'}                       

   {/foreach}
   {/foreach}
{/if}



Hope this helps... :D


It shows tags in all languages, how can I make that it shows tags only in language what are customer in?

Share this post


Link to post
Share on other sites

Artizzz, the results are as: $row['tags'][id_lang]

I don't know what you want to accomplish but adapting the above code will be: {foreach from=$product.tags.1 (where 1 is your language id)

Share this post


Link to post
Share on other sites

Hello, Radu!

I add picture to show my problem. As you see in picture there are 9 tags on this product but really this product have only 3 tags those 6 are clones from other 2 languages and when I modified: "{foreach from=$product.tags.1", it worked but it show only one language tags even I change languages it shows tag in English. I need to make that there will be showed tags depending on language what customer are selected (similar functionality like tags block: if in your chosen language are some tags for this product it's shows if there's no tags then tags block don't even show)

40377_oo2WDE7jCVuzfLGGfSnI_t

Share this post


Link to post
Share on other sites

I understand so instead of 1 we need to place something like $id_lang -> I don't know from my head but I will check later if you can't find it

Share this post


Link to post
Share on other sites

This is what I did

{if $lang_iso == sv} {assign var='lng' value=4}
{else} {assign var='lng' value=1}
{/if}
{assign var='tag1' value=$product.tags[$lng]}


It's a bit ugly, but works

/Mats

Share this post


Link to post
Share on other sites
This is what I did
{if $lang_iso == sv} {assign var='lng' value=4}
{else} {assign var='lng' value=1}
{/if}
{assign var='tag1' value=$product.tags[$lng]}


It's a bit ugly, but works

/Mats


Where I need to put this code? (I tried put it in tlp file but nothing happens)

Share this post


Link to post
Share on other sites

Well you can't just copy it, for one thing this handles my shop which only has Swedish and English, you need to find what numbers are used for the languages you use and change the code according to that.
Second, I only use one tag and it is put into the variable $tag1 that I later use to make it show.
In essence, $lang_iso contains the ISO code for the customer's chosen language, and the code translates $lang_iso into a number, $lng that can be used with $product.tags to grab the tags from only that language.

So something like this in your case

{if $product.tags}
   {if $lang_iso == es} {assign var='lng' value=PUT NUMBER FOR SPANISH HERE}
   {else} {if $lang_iso == fr} {assign var='lng' value=PUT NUMBER FOR FRENCH HERE}
   {else} {assign var='lng' value=1}
   {/if}
   {foreach from=$product.tags[$lng] item=tag1}
   {foreach from=$tag1 item=tag}

      
{$tag|escape:'htmlall':'UTF-8'}                       

   {/foreach}
   {/foreach}
{/if} 



Sorry, a bit short on time ATM, or I'd check the numbers

/Mats

Share this post


Link to post
Share on other sites
Well you can't just copy it, for one thing this handles my shop which only has Swedish and English, you need to find what numbers are used for the languages you use and change the code according to that.
Second, I only use one tag and it is put into the variable $tag1 that I later use to make it show.
In essence, $lang_iso contains the ISO code for the customer's chosen language, and the code translates $lang_iso into a number, $lng that can be used with $product.tags to grab the tags from only that language.

So something like this in your case
{if $product.tags}
   {if $lang_iso == es} {assign var='lng' value=PUT NUMBER FOR SPANISH HERE}
   {else} {if $lang_iso == fr} {assign var='lng' value=PUT NUMBER FOR FRENCH HERE}
   {else} {assign var='lng' value=1}
   {/if}
   {foreach from=$product.tags[$lng] item=tag1}
   {foreach from=$tag1 item=tag}

      
{$tag|escape:'htmlall':'UTF-8'}                       

   {/foreach}
   {/foreach}
{/if} 



Sorry, a bit short on time ATM, or I'd check the numbers

/Mats


THANKS, your code is awesome, but I had little problem with it on the beginnings but I solve it - for more then 2 languages the middle lines(if someone have more then 3 languages then all middle lines) need to make with code
 {elseif $lang_iso == LANGUAGE CHARTERS example - FR } {assign var='lng' value=PUT NUMBER FOR FRENCH HERE} 


instead of your code

   {else} {if $lang_iso == fr} {assign var='lng' value=PUT NUMBER FOR FRENCH HERE}


now on the first look it's working perfect! Thank you again, mohsart. :)

And maybe someone can please tell me how to style it better: I would like to know how to make those tags in line, and for vertical lining if there are 9 tags(like my added picture) how to force to tags what are going out of range of picture height they make second line near the first line ? and how to make those tags to be clicked and displayed tag list for clicked tag?

40435_DosRMrpBTRe5mqVww61m_t

Share this post


Link to post
Share on other sites

Yes a typo there, good you figured it out :-)
For style it's about what you want it to look like...
I use

{l s='Authors'}:
{foreach from=$tag1 item=tag}{$delimiter} {$tag|escape:'htmlall':'UTF-8'}{assign var='delimiter' value=','}{/foreach}


which again is for my shop, and produce a list of authors for a book, eg "Big Book About Something - Authors: Joe Doe, Tom Doe"

Edit: Not really a typo, I'm just not very good at smarty.
My code makes one tag appear as "Authors: John Doe", two tags as "Authors: John Doe, Joe Doe", where the tags are used as authors of books, all on one lite properly comma separated. A bullet list or whatever can be produced with proper html code.

/Mats

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • 9 months later...

Hello everyone,

in gratitude to lafondadebaco, who solved me this problem, I post the solution for putting the product tags in the product-list.tpl, FILTERED BY LANGUAGE (only the product tags corresponding to the current language are displayed).

 

In classes/Product.php, in the getProductProperties function, nearly line 2200:

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

 

In Product-list.tpl:

{if $product.tags}
   {foreach from=$product.tags item=tag1}
   {foreach from=$tag1 item=tag}		
   <a href="{$link->getPageLink('search.php')}?tag={$tag|urlencode}" style="text-decoration:none; font-weight:lighter;background:#f1f1f1;padding:5px 5px 0 5px;float:left;" title="Click aquí para ver todos los productos con este tipo de transporte,">    {$tag|escape:'htmlall':'UTF-8'}   </a>								
   {/foreach}
   {/foreach}
   {/if}

 

and to filter by language, in classes/Tag.php:

public static function getProductTags($id_product, $id_lang = NULL)
{
global $cookie;
$id_lang = $id_lang ? $id_lang : $cookie->id_lang;

if (!$tmp = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT t.`id_lang`, t.`name`
FROM '._DB_PREFIX_.'tag t
LEFT JOIN '._DB_PREFIX_.'product_tag pt ON (pt.id_tag = t.id_tag)
WHERE pt.`id_product`='.(int)($id_product).' AND t.`id_lang` = '.(int)($id_lang)))
return false;
$result = array();
foreach ($tmp AS $tag)
$result[$tag['id_lang']][] = $tag['name'];
return $result;
}

 

Regards

  • Like 2

Share this post


Link to post
Share on other sites
  • 6 months later...

Hi everyone.

 

I am a little lost in this post and I would just like to know the way to insert features of product in product-list.tpl.

I tried soemthing like that.

{foreach from=$features item=feature}

<div id="test">

<span>{$feature.name|escape:'htmlall':'UTF-8'} :</span>   {$feature.value|escape:'htmlall':'UTF-8'}

</div>

{/foreach}

But it didn't work, and I don't know in which php file I have to ask for features as there is no product-list.php...

Thank you for any help !

 

Patrick.

Share this post


Link to post
Share on other sites
  • 1 year later...
  • 11 months later...

Thanks guys ! You saved my day !

I know this must be simple - but - All of my tags are colors and I would like to rename "Tags" to "Colors" but haven't found out where to do that yet?

 

One more hopefully simple question - on the left of the products page (default bootstrap theme) are info, tags, viewed products. How do I change the order? - I would like Tags (colors) listed on top.

 

Ok - One more - how do I change the font color and button color for each tag? Since they're relating to colors I wanted to have each button represent the color in the background.

 

If this is off-topic please direct me to the correct thread.

 

Thanks!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

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