【发布时间】:2017-11-24 20:20:02
【问题描述】:
Magento 2 专家, 您能帮我在 magento 2 产品详细信息页面中隐藏空/NA 属性吗?
非常感谢
【问题讨论】:
标签: attributes hide magento2
Magento 2 专家, 您能帮我在 magento 2 产品详细信息页面中隐藏空/NA 属性吗?
非常感谢
【问题讨论】:
标签: attributes hide magento2
好吧,这是 magento 核心问题:https://github.com/magento/magento2/issues/9961,但您现在可以使用以下解决方案。
从 :/vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml 获取 attributes.phtml 文件
复制此文件并粘贴到您的主题中:/app/design/frontend/[YOUR PACKAGE]/[YOUR THEME]/template/catalog/product/view/attributes.phtml。
搜索以下代码:
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
将上面的代码替换为以下代码:
<?php
$_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!$_attribute->getFrontend()->getValue($_product)) {
continue;
}
?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
以上解决方案在 Magento 2.2 中完美运行
【讨论】: