Jump to content
Minkiu

Display Attribute Quantities in the DropDown

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

Share this post


Link to post
Share on other sites

<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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

<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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More