2013-02-13 52 views
1

我目前正面臨一個至少我無法解決的問題,也許你可以幫我解決問題。prestashop在屬性下拉列表中缺貨

Im顯示所有尺寸的下拉菜單。現在我想在下拉菜單中顯示產品缺貨(缺貨)旁邊的尺寸。

我已經找到一個狙擊至極顯示至極產品缺貨的:

{foreach from=$combinations key=idCombination item=combination} 
    {if $combination.quantity == 0} 
     {assign var=attributes value=','|explode:$combination.list} 
     {foreach from=$groups key=id_attribute_group item=group} 
      {foreach from=$group.attributes key=id_attribute item=group_attribute} 
       {foreach from=$attributes item=attribute name=attribute} 
        {if $id_attribute == $attribute|substr:1:-1} 
         {$group_attribute} - {* if !$smarty.foreach.attribute.last}, {/if *} 
        {/if} 
       {/foreach} 
      {/foreach} 
     {/foreach}     


    {/if} 
{/foreach} 

{/條} {/ if}個

它的工作原理,但我寧願要顯示它在下拉列表中。我怎樣才能得到這個?

更新 - 產生下拉

<div id="attributes"> 
{foreach from=$groups key=id_attribute_group item=group} 
{if $group.attributes|@count} 
<fieldset class="attribute_fieldset"> 
<label class="attribute_label" for="group_{$id_attribute_group|intval}">{$group.name|escape:'htmlall':'UTF-8'} :</label> 
{assign var="groupName" value="group_$id_attribute_group"} 
<div class="attribute_list"> 



------ this is the select ---------------------- 
{if ($group.group_type == 'select')} 
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_selectt" 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> 
------------ select endd ---------------- 



{elseif ($group.group_type == 'color')} 
<ul id="color_to_pick_list" class="clearfix"> 
{assign var="default_colorpicker" value=""} 
{foreach from=$group.attributes key=id_attribute item=group_attribute} 
<li{if $group.default == $id_attribute} class="selected"{/if}> 
<a id="color_{$id_attribute|intval}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value} !important;" title="{$colors.$id_attribute.name}" onclick="colorPickerClick(this);getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}"> 
{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')} 
<img src="{$img_col_dir}{$id_attribute}.jpg" alt="{$colors.$id_attribute.name}" width="20" height="20" /><br> 
{/if} 
</a> 
</li> 
{if ($group.default == $id_attribute)} 
{$default_colorpicker = $id_attribute} 
{/if} 
{/foreach} 
</ul> 
<input type="hidden" class="color_pick_hidden" name="{$groupName}" value="{$default_colorpicker}" /> 
{elseif ($group.group_type == 'radio')} 
{foreach from=$group.attributes key=id_attribute item=group_attribute} 
<input type="radio" class="attribute_radio" name="{$groupName}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} onclick="findCombination();getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">         {$group_attribute|escape:'htmlall':'UTF-8'}<br/> 
{/foreach} 
{/if} 
</div> 
</fieldset> 
{/if} 
{/foreach} 
</div> 
+0

請分享您的下拉菜單的代碼太 – SJousse 2013-02-13 20:39:15

回答

2

下面有一個通過編輯方式/覆蓋產品控制器的代碼。測試Prestashop 1.5.2

在控制器ProductController中,您將看到功能assignAttributesGroups這將處理可用於顯示在視圖上的組/屬性。

// wash attributes list (if some attributes are unavailables and if allowed to wash it) 
if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) 
{ 
    foreach ($groups as &$group) 
     foreach ($group['attributes_quantity'] as $key => &$quantity) 
      if (!$quantity) 
       unset($group['attributes'][$key]); 

    foreach ($colors as $key => $color) 
     if (!$color['attributes_quantity']) 
      unset($colors[$key]); 
} 

您可以在此處看到該屬性已從可用組中刪除。如果您希望它保留在列表中,請重新創建此功能並重新創建此功能。

變化

if (!$quantity) 
    unset($group['attributes'][$key]); 

if (!$quantity) 
    $group['attributes'][$key] .= " Sold Out"; 

有關的Prestashop和壓倒一切的更多信息請參見http://doc.prestashop.com/display/PS15/Overriding+default+behaviors

2

對於PS 1.6.XI認爲是更好地獲得庫存數量智者 ,例如:

查找product.tpl的屬性附加傷害選項名稱:

{$group_attribute|escape:'html':'UTF-8'} 

和替換:

{$group_attribute|escape:'html':'UTF-8'} 
    {if {$group.attributes_quantity[{$id_attribute|intval}]} < 1} 
     - {l s='Out Stock'} 
    {/if} 

並可以顯示屬性名稱 - 缺貨沒有當一個產品屬性修改核心的Prestashop缺貨。

當屬性產品數量小於X時,可以顯示另一個消息。

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

enter image description here