2010-11-03 120 views
2

我已經創建了我想在前端使用的類別屬性。我試圖像訪問產品一樣訪問它,但它似乎不工作。我如何在前端顯示自定義屬性?任何猜測?在前端獲取Magento類別屬性

感謝

+0

什麼數據類型的屬性? – 2010-11-03 09:56:05

回答

6

試試這個:

$cat_attr = $this->getCurrentCategory()->getAttributes(); 
if(array_key_exists('short_description', $cat_attr)): 
    $_shortDescription=$cat_attr['short_description']->getFrontend()->getValue($_category); 
endif; 
2

我會做的第一件事是做下面的代碼的類對象

print_r($category->debug()); 

上這會告訴你,如果該屬性是正裝。如果你沒有看到你的屬性,你可以回去的地方,正在加載的對象控制器,並通過添加這些行之一將它添加到您的選擇:

->addAttributeToSelect('your_attribute') 

這應該載入您的屬性你。

1

很簡單

<?php foreach ($this->getStoreCategories() as $cat): ?> 
<?php $_category=Mage::getModel("catalog/category")->load($cat->getId()); ?> 

現在你應該使用的getImage方法來擷取您的IMG屬性

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/category/' . $_category->getImage() ?>" /> 

<?php endforeach ?> 
2

我有一個自定義屬性,並在前端這種方式得到了顯示它;

$category_id = '10'; 
$attribute_code = 'category_categorycolor'; 
$category = Mage::getModel('catalog/category')->load($category_id); 

echo $category->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($category);