Magento

Get list of product attribute in Magento

# Get list of colors from Magento Installation

Let’s create a file called getcolors.php on Magento root folder.

require_once ( “app/Mage.php” );
umask(0);
Mage::app(“default”);
Mage::getSingleton(“core/session”, array(“name” => “frontend”));
$attribute = Mage::getSingleton(‘eav/config’)->getAttribute(‘catalog_product’, ‘color’);
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
}
print_r($options);

When you excute the file getcolors.php either from shell or browser, It will print the list of color used in product catalog.

Read More...

Magento

Magento – Displaying Additional Product Attributes in Catalog List

Firstly I added new method to class Mage_Catalog_Block_Product_View_Attributes:

function setProduct($productId)
{
if (!Mage::registry('product') && $productId) {
$this->_product = Mage::getModel('catalog/product')->load($productId);
}
}

Then I’ve added to /app/design/frontend/*/*/template/catalog/product/list.phtml this:

<table class="info">
<?php
$add = new Mage_Catalog_Block_Product_View_Attributes();
$add->setProduct($_product->getId());
$_additional = $add->getAdditionalData();
?>
<?php foreach ($_additional as $_data): ?>
<tr>
<th><?php echo $_data['label'] ?></th>
<td><?php echo $_data['value'] ?></td>
</tr>
<?php endforeach; ?>
</table>

Read More...