get an array of all a products attributes in magento

前端 未结 3 1651
青春惊慌失措
青春惊慌失措 2021-02-05 15:32

I cannot figure this out!

I am trying to get a list of a products attributes into an array on the list.phtml page. I have tried everything. I have seen a lot of solution

3条回答
  •  清歌不尽
    2021-02-05 16:16

    I'm guessing you need a list of only visible values. I say "values" because attributes are not the actual values, they are descriptors. The following is the salient parts from Mage_Mage_Catalog_Block_Product_View_Attributes:

    $attributes = $product->getAttributes();
    foreach ($attributes as $attribute) {
        if ($attribute->getIsVisibleOnFront()) {
            $value = $attribute->getFrontend()->getValue($product);
            // do something with $value here
        }
    }
    

    You don't really need to duplicate this though since you can alter/use the template catalog/product/view/attributes.phtml which is already declared on the product view page as attributes block.

提交回复
热议问题