2013-03-19 9 views
5

新しく作成された属性のすべての既存の値をmagento 1.7.0.2で一覧表示しようとしています。 (およびクリックで彼らは、特定の属性値を持つすべての項目をリストアップ、それが今の優先順位ではありませんように、それらをクリック可能なリンクにする)Magento:単一の属性のすべての値を一覧表示する

属性コードは、これまで「アーティスト」

です/アプリ/設計/フロントエンド/デフォルト/テンプレート - で

public function getAllArtists() 
{ 
$product = Mage::getModel('catalog/product'); 
$attributes = Mage::getResourceModel('eav/entity_attribute_collection') 
    ->setEntityTypeFilter($product->getResource()->getTypeId()) 
    ->addFieldToFilter('attribute_code', 'artist'); 
$attribute = $attributes->getFirstItem()->setEntity($product->getResource()); 
$artists = $attribute->getSource()->getAllOptions(false); 
    return $artists; 
} 

とファイルartist.phtml:私は、次のコードでコア/メイジ/カタログ/ブロック/ /アプリ/コード内のファイルArtist.phpを作成しましたこのコードの名前/テンプレート/カタログ/製品:

<ul id="artist_list"> 
    <?php foreach ($this->getAllArtists() as $artist): ?> 
    <li><a href="<?php Mage::getURL() ?>catalogsearch/advanced/result/?&artist;[]=<?php echo $artist['value'] ?>&search;="><?php echo $artist['label'] ?></a></li> 
    <?php endforeach; ?> 
</ul> 
私は、

{{block type="core/template" template="catalog/product/artist.phtml"}} 

と静的ブロック内で呼び出すが、何も表示されない

...

私はこのスレッドからコードを使用:http://www.magentocommerce.com/boards/viewthread/19982/P0/

属性は、上の「可視設定されていますフロントエンドのプロダクトビューページ " と私は../template/product/view.phtmlの各項目の属性値を

<?php echo $_product->getData('artist') ?> 
と呼びます

と値が正しく表示されます。

答えて

20
$name='whatever_your_attribute_name'; 
    $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem(); 
    $attributeId = $attributeInfo->getAttributeId(); 
    $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); 
    $attributeOptions = $attribute ->getSource()->getAllOptions(false); 
    print_r($attributeOptions); 

参考になります:Magento - get all attribute value

1

それだけで

$attribute = Mage::getModel('eav/config')->getAttribute(4,'artist'); 
if($attribute->usesSource()) { 
    $options = $attribute->getSource()->getAllOptions(false); 
    foreach($options as $key=>$value) { 
     if(count($value)==2) { 
      $artists[] = $value['label']; 
     } 
    } 
} 
+0

はまだ働いていない... 私はあなたとパブリック関数のコードを置き換え、それはまだ何も表示文句を言いません。 私はPHPのnoobです、私もあまりにも言わなければなりません – flukee

+0

ああ、静的なブロックでブロックタイプ=カタログ/アーティスト – TaganPablo

+0

はまだ成功しません.. – flukee

関連する問題