2017-01-11 8 views
0

特定のカテゴリIDからすべての製品および製品属性値を正常に表示しました。しかし、私は製品属性ラベルを表示する方法を理解することはできません。属性ラベルはハードコードされていますが、私はそれを自動生成します。特定のカテゴリidのすべての製品、製品属性値および属性ラベルをマゼンタで表示

フロントエンドに表示されるすべての商品属性値とそれぞれのラベルを表示するにはどうすればよいですか?

これまでのところ、これはこれを試してみて、私は

<?php 
$idValue = 10; 
$catagory_model = Mage::getModel('catalog/category')->load($idValue); //where $category_id is the id of the category 
$collection = Mage::getResourceModel('catalog/product_collection'); 
$collection->addCategoryFilter($catagory_model); //category filter 
$collection->addAttributeToFilter('status',1); //only enabled product 
$collection->addAttributeToSelect('*'); //add product attribute to be fetched 
$collection->addStoreFilter(); 
?> 
<table class="full-width-tbl"> 
<thead> 
    <tr> 
     <th>Part Number</th> 
     <th>Model</th> 
    </tr> 
</thead> 
<tbody> 
<?php foreach ($collection as $_product): ?>    
    <tr itemscope itemtype="http://schema.org/IndividualProduct"> 
     <td itemprop="name" style="display:none;"><?php echo $_product->getPart_number() ?></td> 
     <td itemprop="sku"><?php echo $_product->getModel() ?></td> 
    </tr> 
<?php endforeach ?> 
</tbody> 
</table> 

答えて

1

を持っているものです:

これはあなたにAttributelabel-Attributecode-Attributevalue

<?php foreach ($collection as $_product): 

    $product_id = $_product->getId(); 
    $product = Mage::getModel('catalog/product')->load($product_id); 
    $attributes = $product->getAttributes(); 


    foreach ($attributes as $attribute) { 
      $visibility = $attribute->getIsVisibleOnFront(); 
      $attributeLabel = $attribute->getFrontendLabel(); 
      $attributeValue = $attribute->getFrontend()->getValue($product); 
      $attributeCode = $attribute->getAttributeCode(); 
if($visibility){   
echo $attributeLabel . '-' . $attributeCode . '-' . $attributeValue; echo "<br />"; }  

    } 
    endforeach 
    ?> 
+0

を与えるだろう、この方法を私はそれを並べ替えることができ、すべての属性を取得フロントエンドのプロダクトビューのページに表示されているものを表示します。 – rodge

+0

ありがとう!問題が解決しました。 – rodge

関連する問題