如何在“产品"页面上显示属性组名称? [英] How to display Attribute Group Name on Product page?

查看:67
本文介绍了如何在“产品"页面上显示属性组名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了属性集,其中包含更多 Grouped 属性.在admin中,自定义属性会像我创建的那样显示在组中(标签).但是,在产品页面上,所有属性均一起列出,而在列出该组中的属性之前不显示属性组名称.

I created Attribute Sets with more Grouped attributes inside. In admin, the custom attributes are displayed in groups (tabs) like I created them. But, on the product page, all the attributes are listed together, without displaying the Attribute Group Name before listing the Attributes in that Group.

如何显示属性组名称,而不仅是属性?如果可以在默认模板上显示我,我将在我的自定义模板中相应地显示.

How can I display also the Attribute Group names, not only the attributes? If you could show me on the default template, I will do it accordingly in my custom template.

谢谢!

推荐答案

好,我找到了答案,希望对其他人寻找相同的东西有用. 首先,我使用的是Magento 1.5.0. 其次,我在德语此处中找到了答案,并带有扩展名已经创建,但是安装失败. 因此,我用以下代码添加了/app/code/local/Mage/Catalog/Block/Product/View/Attributesgroups.php :

Ok, I found an answer and I hope it will be useful to others in search for the same thing. First, I'm using Magento 1.5.0. Second, I found the answer in German here, with an extension already created, but the installation failed. So, I added /app/code/local/Mage/Catalog/Block/Product/View/Attributesgroups.php with the following code:

<?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/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/view/attributesgroups.phtml 文件,其内容如下:

Then, I created the /app/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/view/attributesgroups.phtml file with the following content:

<?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;?>

最后一步是在第223行中修改/app/design/frontend/default/YOUR_TEMPLATE/layout/catalog.xml ,并替换了

Last step was to modify /app/design/frontend/default/YOUR_TEMPLATE/layout/catalog.xml in line 223, and replaced

<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">

我再说一遍,这个答案不属于我,我只是翻译了发现的内容. 非常感谢,这些美丽的人以简洁明了的答案结束了我三天的搜索工作: WebGuys.DE 另外,感谢@rpSetzer关心的帮助!

I repeat, this answer does NOT belong to me, I just translated what I found. Many thanks to the beautiful people who ended my three days of search with a clean and simple answer: WebGuys.DE Also, thanks to @rpSetzer who cared to help!

这篇关于如何在“产品"页面上显示属性组名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆