获取产品列表属性值的最快方法


The fastest way to get attribute values on product listing

我正在寻找在产品列表页面上获取可配置产品属性值的最有效方法,例如产品的颜色值(来自指定的简单产品)

目前正在考虑为此目的使用catalog_product_flat_n表,但也许有一种更简单或更正确的方法可以做到这一点?我尽量避免使用

$product->getTypeInstance()->getConfigurableAttributesAsArray()

在每种产品上,因为这将是非常缓慢的

感谢

我也遇到了同样的问题,所以我创建了自己的资源模型来从平面表中获取数据,查看下面的代码

  <?php
    class NameSpace_ModuleName_Model_Resource_Colors 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;
        }
    }

希望它能对你有所帮助