1

我目前面临一个我无法解决的问题,也许你可以帮助我。

我正在显示所有尺寸的下拉列表。现在我想在尺寸旁边显示产品缺货(缺货)时的下拉列表。

我找到了一个片段,它显示了哪些产品缺货:

    {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}
{/strip}{/if}

它有效,但我更想在下拉列表中显示它。我怎样才能得到这个?

update - 生成下拉列表的代码

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

4 回答 4

3

对于 PS 1.6.XI 认为最好在 smarty 中获取库存数量,例如:

在 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 时,您也可以显示另一个消息。

于 2014-08-11T11:33:32.723 回答
2

这是通过编辑/覆盖产品控制器的一种方法。在 Prestashop 1.5.2 上测试

在控制器ProductController中,您将看到 functionassignAttributesGroups 这处理可用于在您的视图上显示的组/属性。

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

于 2013-02-15T14:05:03.517 回答
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>

在此处输入图像描述

于 2017-05-10T22:26:54.647 回答
1

Prestashop 1.7.6.4

通过修改 /themes/[YOUR_THEME]/templates/catalog/_partials/product-variants.tpl 文件可以很容易地完成。

{if $group.group_type == 'select'}
        <select
          id="group_{$id_attribute_group}"
          class="form-control form-control-select"
          data-product-attribute="{$id_attribute_group}"
          name="group[{$id_attribute_group}]">
          {foreach from=$group.attributes key=id_attribute item=group_attribute}

            {if {$group.attributes_quantity[{$id_attribute|intval}]} < 1}
              <option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name} - {l s='Sold Out' d='Shop.Theme.Catalog'}</option>
            {else}
            <option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
            {/if}

          {/foreach}
        </select>

您可以更改不可用变体旁边显示的文本以及翻译它。

此外,如果您不希望变体可点击,可以使用 HTML 将其更改为灰色:

{if {$group.attributes_quantity[{$id_attribute|intval}]} < 1}
          <option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if} disabled>{$group_attribute.name} - {l s='Sold Out' d='Shop.Theme.Catalog'}</option>
        {else}
        <option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
        {/if}
于 2020-05-07T09:36:59.457 回答