How to get all attribute of a product. I try to manage this line of code from internet or some other sources where i can easily able to fetch Product name,image,price and description but I failed to fetch all product Frontend and FrontendLabel like color,brand etc.I am new to php.So any help would be appreciate.

    // Get products in category
    require_once('../app/Mage.php');//Path to Magento umask(0);

        $proxy = new SoapClient('http://www.prashant.com/index.php/api/v2_soap/?wsdl'); // TODO : change url
        $sessionId = $proxy->login('prash', 'prashant123@'); // TODO : change login and pwd if necessary

        $products= $proxy->catalogCategoryAssignedProducts($sessionId,$categoryId);


      foreach ($products as $item) { 

        $product2 = Mage::getModel('catalog/product')->load($item->product_id);
        $productMediaConfig = Mage::getModel('catalog/product_media_config');
        $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());


                foreach ($attributes as $attribute) {
                        if ($attribute->getIsVisibleOnFront()) {
                        $attributeCode = $attribute->getAttributeCode();
                        $label = $attribute->getFrontend()->getLabel($product2);        
                        $value = $attribute->getFrontend()->getValue($product2);
                        echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";        

               $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());


        $statusen= Mage_Catalog_Model_Product_Status::STATUS_ENABLED;


      //return array of products
      //echo "<pre>";
      //echo "</pre>";
      echo json_encode($itemDetails);
      echo "error";

2 Answers 2


You can try below code that will work for you.

$block = Mage::app()->getLayout()->createBlock('catalog/product_view_attributes');
    $_helper = Mage::helper('catalog/output');
    $_product = $product2;
    $_additional = $block->getAdditionalData();  
     foreach ($_additional as $_data): 

            echo $block->escapeHtml($this->__($_data['label'])); 
            echo $_helper->productAttribute($_product, $_data['value'], $_data['code']);

For the code seems to be fine,

I think there is some problem with your setting,

For fetching this way your attribute should display yes in view page.

Because I think This is the same kind of code you will get into catalog/product/view/attribute.phtml file

For this setting go to

Catalog->Attribute->Manage Attribute-> click on Your Attribute-> Frontend Properties ->Visible on Product View Page on Front-end set to Yes

In your code remove this if condition and might be It work for you

            foreach ($attributes as $attribute) {
                    //if ($attribute->getIsVisibleOnFront()) { remove if condi
                    $attributeCode = $attribute->getAttributeCode();
                    $label = $attribute->getFrontend()->getLabel($product2);        
                    $value = $attribute->getFrontend()->getValue($product2);
                    echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";        
   // } end remove if condi

May be this issue because of you have not set current store. please set current store and check add below code after Mage::app();

  • its already YES Dec 5, 2016 at 11:33
  • try this code $product2->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($product2) Dec 5, 2016 at 11:40
  • again not working but when i write color in place of 'attribute_code' it shows black and i want it should fetch label name too. Dec 5, 2016 at 11:56
  • @PrashantDas So the code you have written worked only on home page only , let me check detail and I will answer you later for this Dec 5, 2016 at 11:58
  • @PrashantDas check my updated answer Dec 5, 2016 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.