Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Last active August 29, 2015 14:18
Show Gist options
  • Save molotovbliss/dcc8657590ae5a0b8ea0 to your computer and use it in GitHub Desktop.
Save molotovbliss/dcc8657590ae5a0b8ea0 to your computer and use it in GitHub Desktop.
Get attributes via Flat table instead of EAV
<?php
/*
* Get attributes via Flat table instead of EAV alternative to the resource heavy
* $product->getTypeInstance()->getConfigurableAttributesAsArray()
* Source: http://www.atwix.com/magento/custom-resource-model-magento-product-flat-tables/
*/
class Company_Custom_Model_Resource_Flat extends Mage_Core_Model_Resource_Db_Abstract
{
protected $_storeId;
protected function _construct()
{
$this->_init('catalog/product_flat', 'entity_id');
$this->_storeId = (int)Mage::app()->getStore()->getId();
}
public function getData($entityId)
{
$resource = Mage::getSingleton('core/resource');
$select = $resource->getConnection('core_read')->select();
$select
->from($this->getTable(array('catalog/product_flat', $this->_storeId)), '*')
->where('entity_id = :entity_id');
$result = $resource->getConnection('core_read')->fetchAll($select, array('entity_id' => $entityId));
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment