在magento中显示特定类别ID的所有产品,产品属性值和属性标签

时间:2017-01-11 00:58:12

标签: php content-management-system e-commerce magento-1.9

我已成功显示特定类别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 个答案:

答案 0 :(得分: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
     ?>