我在里面创建了更多Grouped属性的属性集.在admin中,自定义属性显示在组(选项卡)中,就像我创建它们一样.但是,在产品页面上,所有属性都列在一起,在列出该组中的属性之前不显示属性组名称.
如何显示属性组名称,而不仅仅是属性?如果您可以在默认模板上显示我,我将在我的自定义模板中进行相应的操作.
谢谢!
好的,我找到了答案,我希望其他人在寻找同样的事情时会有所帮助.首先,我使用的是Magento 1.5.0.其次,我在这里找到了德语的答案,已经创建了扩展,但安装失败了.所以,我使用以下代码添加了/app/code/local/Mage/Catalog/Block/Product/View/Attributesgroups.php:
<?php
class Mage_Catalog_Block_Product_View_Attributesgroups extends Mage_Core_Block_Template
{
protected $_product = null;
function getProduct()
{
if (!$this->_product) {
$this->_product = Mage::registry('product');
}
return $this->_product;
}
public function getAdditionalData(array $excludeAttr = array())
{
$data = array();
$product = $this->getProduct();
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);
// TODO this is temporary skipping eco taxes
if (is_string($value)) {
if (strlen($value) && $product->hasData($attribute->getAttributeCode())) {
if ($attribute->getFrontendInput() == 'price') {
$value = Mage::app()->getStore()->convertPrice($value,true);
} elseif (!$attribute->getIsHtmlAllowedOnFront()) {
$value = $this->htmlEscape($value);
}
$group = 0;
if( $tmp = $attribute->getData('attribute_group_id') ) {
$group = $tmp;
}
$data[$group]['items'][ $attribute->getAttributeCode()] = array(
'label' => $attribute->getFrontend()->getLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
$data[$group]['attrid'] = $attribute->getId();
}
}
}
}
// Noch Titel lesen
foreach( $data AS $groupId => &$group ) {
$groupModel = Mage::getModel('eav/entity_attribute_group')->load( $groupId );
$group['title'] = $groupModel->getAttributeGroupName();
}
return $data;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我创建了/app/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/view/attributesgroups.phtml文件,其中包含以下内容:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additionalgroup = $this->getAdditionalData()): ?>
<div class="box-collateral box-additional">
<h2><?php echo $this->__('Additional Information') ?></h2>
<?php $i=0; foreach ($_additionalgroup as $_additional): $i++; ?>
<h3><?php echo $this->__( $_additional['title'] )?></h3>
<table class="data-table" id="product-attribute-specs-table-<?php echo $i?>">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional['items'] as $_data): ?>
<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 endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table-<?php echo $i?>')</script>
<?php endforeach; ?>
</div>
<?php endif;?>
Run Code Online (Sandbox Code Playgroud)
最后一步是修改第223行中的/app/design/frontend/default/YOUR_TEMPLATE/layout/catalog.xml,然后更换
<block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml">
Run Code Online (Sandbox Code Playgroud)
同
<block type="catalog/product_view_attributesgroups" name="product.attributes" as="additional" template="catalog/product/view/attributesgroups.phtml">
Run Code Online (Sandbox Code Playgroud)
我再说一遍,这个答案不属于我,我只是翻译了我发现的内容.非常感谢那些以干净简单的答案结束了我三天搜索的美丽人物:WebGuys.DE 此外,还要感谢@rpSetzer,他们非常关心!