Magento 如何在产品页面上显示属性组名称?
我创建了属性集,其中包含更多的分组属性。在管理中,自定义属性以组的形式显示,就像我创建的那样。但是,在产品页面上,所有属性一起列出,在列出该组中的属性之前,不显示属性组名称 如何显示属性组名称,而不仅仅是属性?如果可以在默认模板上显示,我将在自定义模板中相应地显示Magento 如何在产品页面上显示属性组名称?,magento,Magento,我创建了属性集,其中包含更多的分组属性。在管理中,自定义属性以组的形式显示,就像我创建的那样。但是,在产品页面上,所有属性一起列出,在列出该组中的属性之前,不显示属性组名称 如何显示属性组名称,而不仅仅是属性?如果可以在默认模板上显示,我将在自定义模板中相应地显示 谢谢大家! 遍历所有属性并创建组数组。在每个组中放置属于它的属性。然后,按照您想要的方式显示它们就很简单了 是一个非常接近您需要的实现。好的,我找到了一个答案,希望它对其他搜索相同内容的人有用。 首先,我使用的是Magento 1.5
谢谢大家! 遍历所有属性并创建组数组。在每个组中放置属于它的属性。然后,按照您想要的方式显示它们就很简单了
是一个非常接近您需要的实现。好的,我找到了一个答案,希望它对其他搜索相同内容的人有用。 首先,我使用的是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;
}
}
感谢您的翻译:为可能需要的人提供补充信息:
对于第一步,如果文件夹/app/code/local/Mage/Catalog/Block/Product/View/不存在,请创建它!使用正确的密码,并将文件Attributesgroups.php放在那里
如果您有不同的存储视图(针对不同的语言),并且希望对每个属性标签使用正确的翻译,则需要执行以下操作:
在文件Attributesgroups.php中
将'label'=>$attribute->getFrontend()->getLabel(),
替换为'label'=>$attribute->getStoreLabel(),
我不知道为什么,但是当我使用$attributes=$\u product->getAttributes()时代码>attributes.phtml中断。如果有人有一个完整的工作示例,那就太好了,因为我认为其他没有php经验的人都想知道如何做到这一点。
<?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;?>
<block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml">
<block type="catalog/product_view_attributesgroups" name="product.attributes" as="additional" template="catalog/product/view/attributesgroups.phtml">