当我们上传一个产品时,有一个默认属性设置为“默认”,在常规选项卡中,有许多默认属性,如下图所示:
好吧,我添加了一个名为“size”的自定义属性,当我将“size”拖到左侧的常规选项卡时,这意味着产品还有一个属性。如果我想在前端页面的产品视图页面中显示尺寸属性,我必须输入代码:“$_product->getAttributeText('size')”,如果我添加了很多自定义属性,我必须输入很多代码是手动的。所以,我的问题是如何自动显示所有自定义属性,而不是手动一一添加?
当我们上传一个产品时,有一个默认属性设置为“默认”,在常规选项卡中,有许多默认属性,如下图所示:
好吧,我添加了一个名为“size”的自定义属性,当我将“size”拖到左侧的常规选项卡时,这意味着产品还有一个属性。如果我想在前端页面的产品视图页面中显示尺寸属性,我必须输入代码:“$_product->getAttributeText('size')”,如果我添加了很多自定义属性,我必须输入很多代码是手动的。所以,我的问题是如何自动显示所有自定义属性,而不是手动一一添加?
这已经由 magento 完成。将您的属性标记为在前端可见,仅此而已。
查看路径 app/design/frontend/yourtheme/default/template/catalog/product/view 中的模板 attributes.phtml
<?php if($_additional = $this->getAdditionalData()): ?>
<!--h2><?php echo $this->__('Additional Information') ?></h2-->
<div class="data-table accordion" id="product-attribute-specs-table">
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<div class="clearer <?php echo $this->htmlEscape($this->__($_data['label'])) ?>">
<div class="trigger"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></div>
<div class="triggerContent" style="display: none;"><span><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></span></div>
</div>
<?php } ?>
</div>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
您需要将默认文件从 /app/design/frontend/base/default/template/catalog/product/view 复制到您的主题目录
/public_html/app/design/frontend/default/yourtheme/template/catalog/product/view