Jump to content
thirty bees forum
  • 0

How to check whether a product has combination or not with Smarty


Question

Posted (edited)

Hi, I am modifying the Niara theme and in the `<span class="price product-price">` of `product-list-item.tpl` I want to add a label to products that have combinations.

I have seen that in `product.tpl` there is this line: `{if isset($combinations) && $combinations}`, I have tried add this: `{if isset($product.combinations) && $product.combinations}From{/if}` but it does not seem to work, is there some similar method?

Note that I am purposely avoiding the "Advanced EU Compliance" module as it seems to cause some problems I do not want to debug. I am aware that module has an option like this.

Edited by Jeffrey de Bruijn

3 answers to this question

Recommended Posts

  • 1
Posted

id_product_attribute is the default attribute id of the product, if the product has any attributes/combinations.

if no attributes/combinations exists for the product it will return 0.

when you do conditional check 0 counts as false.

to be more accurate in the case will be better to check that the integer value of the id_product_attribute is greater than 0.

the reason you cannot call same "object properties/array keys" like "combinations" is because those variables are in most cases injected to the templates as smarty variables by php code in specific parts.

for exmaple: in product.tpl most of the variables that available in the template comes from ProductController (FrontController)

  • Like 1
  • 0
Posted (edited)
2 hours ago, wakabayashi said:

Does it work with {$product.id_product_attribute}?

I tried and from my limited testing it seems to be working as intended (thank you) but I really don't understand the logic:

How does this work?

`$product.id_product_attribute` is true as long as the product has one attribute? What does the `id_product_` refer to?

And why does the "method" `.combinations` not work?

Edited by Jeffrey de Bruijn

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