Magento2有的产品属性为空 N/A,如何修改为不显示?
这需要修改你的主题文件.
首先找到你模板下控制产品属性显示的文件:
app/design/{Packagename}/{themename}/Magento_Catalog/templates/product/view/attributes.phtml
注意 /{Packagename}/{themename}/,需要修改成你的主题路径,比如 /Magentochina.org/magento-theme/
修改之后完整的代码为:
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct()
?>
<?php if ($_additional = $block->getAdditionalData()): ?>
<div class="additional-attributes-wrapper table-wrapper">
<table class="data table additional-attributes" id="product-attribute-specs-table">
<caption class="table-caption"><?php echo __('More Information') ?></caption>
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php $_dataVal = $_helper->productAttribute($_product, $_data['value'], $_data['code']);?>
<?php if ($_dataVal != 'N/A'): ?>
<?php if (is_numeric($_dataVal) == true): ?>
<?php $_dataVal = number_format($_dataVal, 2, '.', '');?>
<?php $_dataVal = substr($_dataVal, -3) == ".00" ? substr($_dataVal, 0, -3) : $_dataVal;?>
<?php endif;?>
<tr class="<?php /* @escapeNotVerified */echo $block->escapeHtml(__($_data['code'])) ?>">
<th class="col label" scope="row"><?php echo $block->escapeHtml(__($_data['label'])) ?></th>
<td class="col data" data-th="<?php echo $block->escapeHtml(__($_data['label'])) ?>"><?php echo $_dataVal ?></td>
</tr>
<?php endif;?>
<?php endforeach;?>
</tbody>
</table>
</div>
<?php endif;?>
然后保存退回到Magento的根目录执行命令:
bin/magento ma:en && bin/magento ca:cl && chmod -R 777 . && chown -R www:www . && bin/magento se:di:co &&bin/magento se:st:de && chmod -R 777 . && chown -R www:www . && bin/magento ma:dis
等待刷新缓存的命令执行完成后,刷新页面,检查功能是否实现.
如果没有显示N/A,而是显示的No,你可以看下这个文件:
vendor/magento/module-catalog/Block/Product/View/Attributes.php
希望可以帮助到你.
1 个赞