0

I want to get a list of all attributes that do have the value Used in Product Listing and Used for Sorting in Product Listing set to Yes.

How can I easliy get all attributes with this value?

2 Answers 2

1

Try this

$readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = $readConnection->select()
    ->from($this->getResource()->getTableName('catalog_eav_attribute'))
    ->where('used_in_product_listing = ?', 1)
    ->where('used_for_sort_by = ?', 1);
$results = $readConnection->fetchAll($query);

$results will be array of database rows

If you need attribute_code you should join that with eav_attribute table, using attribute_id field

0
2

Use the following code,you can easily get all attributes with specific value.

$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
$productAttrs->addFieldToFilter('used_in_product_listing',1);
$productAttrs->addFieldToFilter('used_for_sort_by',1);
foreach($productAttrs as $_attr)
{
    echo $_attr->getAttributeId()."-".$_attr->getAttributeCode();
    ...........
    ...........
}

This is one of the easiest way to get all details about each attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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