2012-07-31 72 views
2

我在寻找最有效的方法属性值来获得配置的产品属性值对产品列表页面,例如颜色值的产品(从分配简单的产品)让产品上市

的最快方法目前正在研究利用catalog_product_flat_n表来达到这个目的,但也许有一个更容易或更正确的方法来做到这一点?我试图避免使用

$product->getTypeInstance()->getConfigurableAttributesAsArray() 
对每一件产品

,因为这将是非常缓慢的

感谢

+0

正确的ANS有帮助对于你的问题将根据“最有效”和你想要的属性数据(位置,标签等)的含义而有所不同。 – benmarks 2012-07-31 11:17:21

+0

如果您只处理渲染范围中的单个产品,这正是View-inject可配置的product.info'块中发生的情况。 – benmarks 2012-07-31 11:54:01

+0

我的目标是检索像黑色,绿色等颜色值,不幸的是它不是针对单个产品,而是针对类别产品列表。感谢您的答复! – Zifius 2012-07-31 12:12:13

回答

1

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

<?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; 
     } 
    } 

希望它会为你

+0

有了这个,你在类别模板中改变了什么? – Dor 2013-09-18 13:51:59