【问题标题】:Display all product, product attribute value and attribute label of specific category id in magento在magento中显示特定类别id的所有产品、产品属性值和属性标签
【发布时间】:2017-01-11 00:58:11
【问题描述】:

我已成功显示来自特定类别 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>

【问题讨论】:

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


    【解决方案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
         ?> 
    

    【讨论】:

    • 这获取所有属性,我如何对其进行排序以仅显示那些在前端产品视图页面上设置为是的?
    猜你喜欢
    • 1970-01-01
    • 2021-06-13
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多