繁体   English   中英

获取有关magento类别view.phtml的特定属性

[英]Get specific attribute on magento category view.phtml

我正在尝试在Magento类别页面上创建Asos样式标题。

在此框中,我提取了类别标题和类别说明,还介绍了如何从分层导航中将特定属性提取到类别view.phtml页面中。

此刻我有

<?php $prod = Mage::getModel('catalog/product')->load($productId); $att = $prod->getResource()->getAttribute('product')->getFrontend()->getValue($prod); echo $att; ?>

但是,它只是拉出“ No ”一词,而不是它在此特定类别的分层导航中显示的属性。

尝试这个:

Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'attribute_code', $storeId);

感谢@Daniel Kocherga这里提供原始答案。

从代码/核心/法师/目录/块/产品/视图/attributes.php

   public function getAdditionalData(array $excludeAttr = array())
    {
        $data = array();
        $product = $this->getProduct();
        $attributes = $product->getAttributes();
        foreach ($attributes as $attribute) {
//            if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
            if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
                $value = $attribute->getFrontend()->getValue($product);

                if (!$product->hasData($attribute->getAttributeCode())) {
                    $value = Mage::helper('catalog')->__('N/A');
                } elseif ((string)$value == '') {
                    $value = Mage::helper('catalog')->__('No');
                } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
                    $value = Mage::app()->getStore()->convertPrice($value, true);
                }

                if (is_string($value) && strlen($value)) {
                    $data[$attribute->getAttributeCode()] = array(
                        'label' => $attribute->getStoreLabel(),
                        'value' => $value,
                        'code'  => $attribute->getAttributeCode()
                    );
                }
            }
        }
        return $data;
    }
}

相当确定这是负责显示带有属性的“否”或“不适用”的部分

我不确定,但请参阅下面的URL。 我认为这对您有很大帮助。

如何在类别中向产品网格添加属性

http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/add-attributes-to-product-grid

Magento属性:每个类别使用不同的可过滤属性

http://www.human-element.com/Blog/ArticleDetailsPage/tabid/91/ArticleID/68/Magento-Attributes-Using-Different-Filterable-Attributes-Per-Category.aspx

在产品页面上获取Magento类别属性的数据

http://spenserbaldwin.com/magento/get-data-for-new-magento-category-attribute

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM