我正试图在我的Magento类别页面上创建一个Asos风格的标题。
在这个框中,我已经拉入了类别标题和类别描述,我还了解了如何从分层导航中拉入特定属性到类别视图.html页面。
目前我有
<?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在这里给出的原始答案。
来自code/core/mage/cacatalog/block/product/view/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;
}
}
可以肯定的是,这是显示属性的"否"或"N/a"的责任部分
我不确定,但请参阅下面的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