1

Hi basically I need to echo out all the products attributes in an order. I get all the attributes as follows however if the attribute is not set it says its getValue() is "No". The issue is some attributes are actually Yes or No soI can't see which are actually set and which aren't! Code below:

List attributes and values:

  $productId = 355;
  $product = Mage::getModel('catalog/product')->load($productId);
  $attributes = $product->getAttributes();

  foreach ($attributes as $attribute) {
  if ($attribute->getIsVisibleOnFront()) {
  $label = $attribute->getFrontend()->getLabel($product);
  $value = $attribute->getFrontend()->getValue($product);
    echo $label . ': ' . $value .'<br />';
  }
  }

This then spits out the following where only Colour is actually set backend. Any that aren't set don't need to be shown here!

Colour: Silver
Restrictor: No
Brand: No
Length: No
Split: No
Stack Height: No
...
1

You can use this :

   $productId = 355;
  $product = Mage::getModel('catalog/product')->load($productId);
  $attributes = $product->getAttributes();

  foreach ($attributes as $attribute) {
  if ((string)$attribute->getFrontend()->getValue($product) != '' and $attribute->getFrontend()->getValue($product) != 'N/A'):
  if ($attribute->getIsVisibleOnFront()) {
  $label = $attribute->getFrontend()->getLabel($product);
  $value = $attribute->getFrontend()->getValue($product);
    echo $label . ': ' . $value .'<br />';
  }
  }

or in your Mage_Catalog.csv set empty values to this:

N/A,""
No,""

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.