首页 > 解决方案 > 将类添加到缺货变体

问题描述

我需要将 CSS 类添加到缺货的变体中,这样我就可以事先知道哪个变体有库存或没有库存。

我一直在检查详细信息页面(特别是 buy_container.tpl 文件),看看那里是否有线索。我使用 var dump 检查$sArticle.sConfigurator但它没有说明其中一个变体是否缺货。我还检查了$sArticle.instock$sArticle.isAvailable但由于详细信息页面使用 ajax 重新加载数据,这些变量仅在选择缺货变体后才起作用,我需要事先知道哪个变体缺货.

这是我需要添加 CSS 类的地方:

{foreach $sConfigurator.values as $configValue}

   {if !{config name=hideNoInstock} || ({config name=hideNoInstock} && $configValue.selectable)}

     <div class="variant--option {if $outofstock}OUT-OF-STOCK{/if} {if $configValue.selected}variant-selected{/if}">

        <input type="radio"
          class="option--input"
          {if $configValue.selected} checked="checked"{/if}
          value="{$configValue.optionID}"
          name="group[{$sConfigurator.groupID}]"

          {if $theme.ajaxVariantSwitch} 
          data-ajax-select-variants="true"{else} 
          data-auto-submit="true"{/if} />
          {$configValue.optionname}{if $configValue.upprice} {if $configValue.upprice > 0}{/if}{/if}

     </div>
  {/if}

{/foreach}

任何线索将不胜感激,谢谢。

标签: shopware

解决方案


尝试使用选择配置器。使用此配置器,此信息将可用。参见:https ://github.com/shopware/shopware/blob/5.5/themes/Frontend/Bare/frontend/detail/config_variant.tpl#L31

在此处输入图像描述

没有其他配置器将提供此数据。当您想使用其他配置器时,您需要自己实现这样的变量/函数。


推荐阅读