user2153898
user2153898

Reputation: 11

Prestashop 1.6 quantity check

Please help me to solve one problem. On my Prestashop 1.6.0.14 I'm trying to check quantity in product.tpl Under the section:

<p id="add_to_cart" {if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE}style="display:none"{/if} class="buttons_bottom_block">
<button type="submit" name="Submit" class="exclusive lmromancaps">{l s='Add to cart'}</button>
</p>   

I'm trying to add code:

{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE }
<input type="button" class="exclusive lmromancaps b1c" value="Order">
{else}
<input type="button" class="exclusive lmromancaps b1c" value="Quick buy">
{/if} 

But the condition when the product doesn't have quantity never happens. This code only working for product which doesn't have any attributes and features, but for products with features and attributes I can't check the quantity.

For example if product has attributes, Color 1, quantity = 1, Color 2, quantity = 0, my code doesn't see that Color 2 has no quantity, it see that it has quantity. Please help me to do it, what I'm doing wrong? Thanks.

Upvotes: 0

Views: 1051

Answers (1)

Serge P
Serge P

Reputation: 1863

In product.tpl you have access to $combinations (product attributes) that contains all combinations data including quantity:

{foreach from=$combinations item=combination}
    {$combination->quantity} 
{/foreach}

from other side, by default most prestashop themes use "onpage interactive attributes choosing" (maybe incorrect words, my bad English, sorry), I mean when you click on e.g. on Color you can see "stock" without requests to server etc. so in template you may see something like:

{addJsDef combinations=$combinations}
{addJsDef combinationsFromController=$combinations}

and you have access to e.g. combinationsFromController variable in your javascript code:

for(i in combinationsFromController) { 
   console.log(combinationsFromController[i].quantity);
}

Upvotes: 1

Related Questions