Jump to content

Display Attribute Quantities in the DropDown


Minkiu

Recommended Posts

Hello everyone,

 

I'm facing a problem, which after looking (searching) Google and the Forums couldn't find a solution, I found similar problems or related but none seem to do for me.

 

What I need to achieve is this: look the attatched image :D

 

Explanation:

I want to display the Quantity of stock of each of my combinations as shown in the image.

So far I believe I've to add a "simple" line here (in product.tpl):

 <select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select" onchange="findCombination();getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if};">
                                    {foreach from=$group.attributes key=id_attribute item=group_attribute}
                                        <option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'htmlall':'UTF-8'}">{$group_attribute|escape:'htmlall':'UTF-8'}</option>
                                    {/foreach}
 </select>

In the <option> tag, but I don't figure out how exactly retrieve the quantity of each attribute.

 

So anyone know how to deal with this? Or maybe it's possible with the Advanced Stock Managment without having to code? :/

 

Thanks in advance!

 

Cheers.

post-633708-0-83414700-1380185329_thumb.png

Link to comment
Share on other sites

  • 1 month later...

<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select" onchange="findCombination();getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if};">
{foreach from=$group.attributes key=id_attribute item=group_attribute}

<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'htmlall':'UTF-8'}">{$group_attribute|escape:'htmlall':'UTF-8'} {$group.attributes_quantity[{$id_attribute|intval}]}</option>
{/foreach}
</select>

 

this will display the quantity {$group.attributes_quantity[{$id_attribute|intval}]}

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

Does anyone have a solution for this in prestashop v1.6? I know that the database structure has changed.  Not sure which version the original solution was for, but I'd like to have the inventory display next to the attribute name in the drop down.  

 

Does anyone have any ideas on how I can achieve this?

 

Thanks!

Link to comment
Share on other sites

  • 6 months later...

The dahda solutions worked for my in the product.tpl, I am looking for a solution for product_list.tpl, integrated with the template.

 

I have the solution to display the array for all attributes, changing the id of the category you want

 

 

$category = new Category(14,(int)Context::getContext()->language->id);
 
$nb = (int)(Configuration::get('MOD_NBR'));
 
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));
 
 
 
foreach ($products as $key=>$row)
{
    $combi[] =array(
                 
                           'id_product' =>  $row['id_product'],
                           'id_product_attribute' => $row['id_product_attribute'],
                           'reference' =>  $row['reference'],   
                           'link_rewrite'=>$row['link_rewrite'],         
                           'link'=>$row['link'],                             
                           'id_image'=>$row['id_image'],                             
                           'name'=>$row['name'],
                           'price'=>$row['price'],
                           'quantity_all_versions'=>$row['quantity_all_versions'],
 
                           'datos_atr'=> $this->getProductAttributeCombinations($row['id_product'], (int)$this->context->language->id),
 
                                                            
 
                  
                 
                );                
}
 
 
 
//$combinations= $this->getProductAttributeCombinations($products);
// echo ('hola');print_r($products);
$this->context->smarty->assign (array(
    'products'=> $products,
    'combinations'=> $combinations,
     'combi' =>$combi,
    ));
 
 
 
 
adding this function 
 
public function getProductAttributeCombinations($product) {
    $combinations = array();
 
   
        $product = new Product ($product, $this->context->language->id);
 
        $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id);
    
 
 
 
    return $combinations;
}
 
 
 
 
 
This return the array of products whit their attributes inside,in another array, in with I have the data of quantity, but, I dont know if exist a faster solution integrated with product list.tpl that display the quantities of the attributes for this product
Link to comment
Share on other sites

  • 1 month later...

<select class="form-control attribute_select no-print" name="{$groupName}" id="group_{$id_attribute_group|intval}">
                                                        {foreach from=$group.attributes key=id_attribute item=group_attribute}
                                                            {if ($group.attributes_quantity[{$id_attribute|intval}] <= 0)}
                                                                {$disabledvar = "disabled"}
                                                                {$esgotado = "Esgotado"}
                                                            {else}
                                                                {$disabledvar = ""}
                                                                {$esgotado = ""}
                                                            {/if}    
                                                    
                                                            <option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'html':'UTF-8'}" {$disabledvar}>{$group_attribute|escape:'html':'UTF-8'} {$esgotado}</option>
                                                        {/foreach}
                                                    </select>

 

 

prestashop.png

Edited by wesleifelix (see edit history)
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 years later...
  • 3 months later...

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