Jump to content

Specific feature variables callout


Recommended Posts

Hello guys,

----- Prestashop 1.7.6

I am trying to callout a specific feature, to be more exact:

- I have a feature with ID 500 and I want to show it below the Buy Button in Product List

- I tried a part of code to show on product.tpl (category products) to show a specific feature below the Buy Button if the product has the required Feature.

So far, I had this:

{foreach from=$product.features item=feature}
<tr class="{cycle values="odd,even"}">
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
{/if}
</tr>
{/foreach}

The above code actually show the whole features below the Buy Button. I want to call a function as below

{if $feature.id_feature_value == 500}

but this doesn't actually do anything. I've searched on every forum with every possible answer, but every each one has nothing to do with calling a single feature.

 

Link to comment
Share on other sites

  • 2 weeks later...
On 10/29/2020 at 1:27 AM, PrestaManiacs said:

You can give a var_dump of $ product.features, to see exactly what it contains, to be able to put the correct condition.
Anyway, for sure, you have to put {if $feature.id_feature== 500}.

Prestashop by default has a psco_feature mysql field and another one called psco_feature_value inside of which id_feature_value are written. Unfortunately, calling out each and every possibility resulted in nothing.

 

On 10/23/2020 at 12:46 AM, inowgsm said:

{if $feature.id_feature_value == 500}

Is calling a certain Feature, not its value. I want to show if certain value is met by product and none if its not met. So the above quote is not correct aswell. The correct one for showing the Feature if available is {if $feature.id_feature == 10}

 

Also

 

{if $feature.value|escape:'html':'UTF-8' == TEXTVALUE}

will actually show to those products that met that value.

But the trigger for the ID still doesnt happen.

But thanks for the help. anyway!

Link to comment
Share on other sites

{foreach from=$product.features item=feature}
{if (in_array($feature.value, array("FEATURE1", "FEATURE2")))}
<tr class="{cycle values="odd,even"}">
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
</tr>
{/if}
{/foreach}

This is a correct way of doing it based on the value name, not the id. If somebody can find a better way, please let me know!

Link to comment
Share on other sites

  • 2 years later...

Hi, i'm trying to do something similar on order-carrier.tpl (ps1.6). 

I would like to change this code in order to check if the feature called "giftwrap" id 25 has a value "true", any clue ? 

Here is my current code that checks product.upc instead but i'd like to check if givewrap feature for one of the products in the cart is set to true. 

{assign var="show_gift" value=false}
{foreach $cart->getProducts() as $product}
{if $product.upc == 12345}{$show_gift = true}{/if}
{/foreach}
{if $giftAllowed && $show_gift}

 

Link to comment
Share on other sites

On 12/9/2022 at 9:28 PM, rafaelfff said:

Hi, i'm trying to do something similar on order-carrier.tpl (ps1.6). 

I would like to change this code in order to check if the feature called "giftwrap" id 25 has a value "true", any clue ? 

Here is my current code that checks product.upc instead but i'd like to check if givewrap feature for one of the products in the cart is set to true. 

{assign var="show_gift" value=false}
{foreach $cart->getProducts() as $product}
{if $product.upc == 12345}{$show_gift = true}{/if}
{/foreach}
{if $giftAllowed && $show_gift}

 

It is solved, here is the working piece of code, but the product class was overridden on my project : 

<!-- custom code for gift codes -->	
{assign var="show_gift" value=false}
{foreach $cart->getProducts() as $product}
{assign var="features" value=Product::getFrontFeaturesStatic(Context::getContext()->language->id, $product.id_product)} 
{foreach $features as $feature}
{if $feature.id_feature == 25 && $feature.value == true}{$show_gift = true}{/if}
{/foreach}
{/foreach}
{if $giftAllowed && $show_gift}
<!-- end custom code for gift codes -->	

 

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