I want to check whether the "use default value" flag is set for a specific product attribute in the admin for a specific store view.

If I have the full product model, I can easily check it like that:

$product = Mage::getModel('catalog/product')->setStoreId($storeViewId)->load($productId);
$hasStoreViewSpecificValue = $product->getExistsStoreValueFlag('my_attribute');

Is it possible to get this information in a smart way without loading the whole product (optimally without any direct SQL queries, but if there is no other way...)?


Thanks @DavidManners for the hint. In the end, it was easier to look how it is done Mage_Catalog_Model_Resource_Abstract::_setAttributeValue though. I came up with the following script which checks if a product has the "Use Default Value" flag set for a specific attribute:


ini_set('display_errors', '1');

require_once 'app/Mage.php';

$store = 7;
$entityId = 15087;
$attributeCode = 'meta_title';

// easy with loading the whole product
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->setStoreId($store)->load($entityId);
echo 'Has Product a Store View Specific Value? ';

// tricky to do it without loading the whole product
$adapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$table = $attributeModel->getBackend()->getTable();
$entityTypeIdField = Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getEntityIdField();
$select = $adapter->select()
    ->from($table, array())
    ->where($entityTypeIdField . ' =?', $entityId)
    ->where('attribute_id =?', $attributeModel->getId())
    ->where('store_id =?', $store)
$values = $adapter->fetchAll($select);
echo 'Has Product a Store View Specific Value? ';
if (empty($values)) {
} else {

I did not test it, but the second version should be much faster as the product does not have to be fully loaded.


You could do this in a similar way to the way Mage_Catalog_Model_Resource_Abstract::getAttributeRawValue works.

  1. Get the attribute table information,
  2. Build your select with the store id,
  3. Simply forget the default check that is normally added in getAttributeRawValue if you really do not care about it,

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.