Categories


Archives


Recent Posts


Categories


Finding the Right EAV Attribute Table

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Need to know the name of an EAV table that an attribute is stored in? Get an instance of the model class,

$customer = Mage::getModel('customer/customer');            

then get a reference to its resource object,

$entity = $customer->getResource();

and use the eav/config service model’s getCollectionAttribute method to create an instance of the attribute object.

$attribute = Mage::getSingleton('eav/config')->getCollectionAttribute($entity->getType(), 'firstname');

With all that in place call the attribute object’s getBackendTable method.

var_dump($attribute->getBackendTable());

My main use for this is when I need to write custom queries for reporting and want to be absolutely sure I’m getting the right table. Of course, I’m also going to need the attribute ID if I want to grab the right row. That’s available via

$attribute->getId()

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 30th September 2011

email hidden; JavaScript is required