1

I just display my attributes on the PLP page, but the attributes duplicates or mismatch, actually I am using $attributes = $_product->getAttributes(); for getting appropriate attributes, but my attributes duplicates.

enter image description here

Instead of using this -> $attributes = $_product->getAttributes(); what is the best way to get products attributes.

complete code : https://justpaste.it/290fr Applied on list.phtml page.

0

Please give a try with the below code in your list.phtml to get product attributes.

$product_id = $_product->getId();
$product = Mage::getModel('catalog/product')->load($product_id);
$attributes = $product->getAttributes();

foreach ($attributes as $attribute) { 
    $attributeLabel = $attribute->getFrontendLabel();
    $value = $attribute->getFrontend()->getValue($product);
    echo $attributeLabel . '-' . $value; echo "<br />";
}
  • It's not a good idea to load() inside a loop though... – simonthesorcerer Oct 17 at 9:29
  • @simonthesorcerer Yes, you're right, but how can we get all attributes associated with the product? – Sumit Oct 17 at 9:32
  • In the backend, simply set each attribute that you want to show in the list as „visible in product listing“. This way, the magento collection will load the attribute automatically. – simonthesorcerer Oct 17 at 9:56
  • Yes, that's correct if we have the attribute code to display, but what if I need all the attributes assigned to the product dynamically? – Sumit Oct 17 at 9:59
  • 1
    simply set that setting for all attributes you need. They get added to the collection, and you can get the values from the product then. No need to load it separately. – simonthesorcerer Oct 17 at 10:11

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.