1

如何在产品列表视图中获取当前自定义类别属性值?我正在尝试这样

$attribute = Mage::getModel('catalog/category')->getAttributes();

我看到它在那里,但如何得到它?我的自定义属性名称是 catalog_pdf

也尝试过这种方式,但一无所获:

$attribute = Mage::getModel('catalog/category')->getAttribute('catalog_category','catalog_pdf');
4

2 回答 2

2

这应该有效。如果您在产品列表中,那么您应该拥有当前类别

Mage::registry('current_category');

所以这样做:

$category = Mage::registry('current_category');
if ($category){ //this is necessary in case you are in a product listing that is's not a category
   $value = $category->getData('catalog_pdf');//catalog_pdf is the attribute code
   //or
   //$value = $category->getCatalogPdf();
}
于 2013-09-04T12:00:38.423 回答
0

这应该有效:

$id = $this->getCurrentCategory()->getId();

$category = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getCode()->getId())->load($id);
echo $category->getData('catalog_pdf');
//or
echo $category->getCatalogPdf();

编辑以包括缺少的 get

于 2013-09-04T12:05:16.523 回答