# Product Combinations -> QUANTITY (Specific for combinations) - tpl

## Recommended Posts

Dear Prestashop users,

There are many questions for this matter and I would like to also post mine.

As far as I have seen there is not a sufficient answer to that.

I am using Prestashop 1.5 and I have some products with combinations.

We have developed a specific system to check the availability of each product based on its combination.

The problem is that if the product has combinations then the quantity is the sum of all the combinations.

For example

I have a PRODUCT with 2 combinations

Combination 1 = 10 pieces

Combinations 2 = 15 pieces

If quantity = 10 pieces then the availability should be low

If quantity = 15 pieces then the availability should be middle

but the result is quantity = 25 pieces which means high

Is it possible to get a combinations specific quantity within a TPL file?

##### Share on other sites

Solved it!

You can tweak product.js and get the combinations quantity.

##### Share on other sites

• 2 weeks later...

Hi, can you, please, describe how did you solve it?

##### Share on other sites

Absolutely!

We have two files

product.tpl

and product.js

First, in product.js you can get the combination number with this code below for example

```
selectedCombination['quantity'] = combinations[combination]['quantity'];

if (selectedCombination['quantity'] <= 0){

}else if (selectedCombination['quantity'] >= 23){

}else if (selectedCombination['quantity'] >= 100){

}

```

then in product.tpl you should add a specific #availability [iD to your div or span or whatever you want] to display what you want. for example

```{if isset(\$groups)} <!-- this checks if there are combinations -->
<span id="availability"></span> <!-- this shows the html text of \$('#availability').html  -->

{else}

DO what you are supposed to do
```

I hope I have helped!

##### Share on other sites

Actually that is not that I really thought. In my project I need to show quantity of each combination (i'm selling spray paint for me it's just color), and I have no idea how to display quantity of each color.

##### Share on other sites

Just display the selectedCombination['quantity'] with javascript.

##### Share on other sites

Thanks for help, but I got it with <p>{\$group.attributes_quantity[{\$id_attribute|intval}]|escape:'html':'UTF-8'}</p> added to product.tpl

• 1
##### Share on other sites

thats great thanks for sharing!

##### Share on other sites

• 1 month later...

Absolutely!

We have two files

product.tpl

and product.js

First, in product.js you can get the combination number with this code below for example

```
selectedCombination['quantity'] = combinations[combination]['quantity'];

if (selectedCombination['quantity'] <= 0){

}else if (selectedCombination['quantity'] >= 23){

}else if (selectedCombination['quantity'] >= 100){

}

```

then in product.tpl you should add a specific #availability [iD to your div or span or whatever you want] to display what you want. for example

```{if isset(\$groups)} <!-- this checks if there are combinations -->
<span id="availability"></span> <!-- this shows the html text of \$('#availability').html  -->

{else}

DO what you are supposed to do
```

I hope I have helped!

In what line of product.js you put the code?

##### Share on other sites

• 1 year later...

I try this code in PS 1.6 but it is not working, can you please help me, step by step, what i have to do? And where i have to put code in product.JS ? THANKS!

##### Share on other sites

• 2 years later...

I need this as well .

## Create an account

Register a new account