2012-02-25 53 views
2

我试图根据与其关联的简单产品的属性显示分组产品列表。现在我在做类似下面简单和分组产品之间的内部连接按简单产品(Magento)的属性筛选


- Create a collection of simple products and add attribute filters like color,brand etc., like below 

$productCollection = Mage::getModel('catalog/product')->getCollection() 
     ->addStoreFilter(Mage::app()->getStore()) 
     ->addAttributeToFilter($aname,$avalue) 
     ->addAttributeToFilter('type_id', array('eq' => 'simple')) 
     ->addAttributeToFilter(ATTRIBUTE_CODE,ATTRIBUTE_VALUE_ID); 
     (->addAttributeToFilter('color',5)) 

- Obtain all resultant ids and get its parent ids using the below 
     Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($productCollection->getAllIds()); 

- Read the parent ids from above object and show the result in a custom grid that i created 

- Created a paging logic for parent ids and do paging in view file 

这个逻辑实在耗费更多的时间,有没有什么办法,我可以做所有这些在一个单一的集合?可能是简单和分组产品之间的内连接方法!

请建议。

感谢, 巴兰

回答

0

这取决于你想过滤的属性。
Magento已经准备好用简单的产品属性过滤分组产品的数据。
它存储在catalog_product_index_eav
但是这些属性应该在magento admin中标记为“可过滤”。

/** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */ 
$productCollection = Mage::getModel('catalog/product')->getCollection(); 
$productCollection->addStoreFilter(Mage::app()->getStore()) 
    ->addAttributeToFilter('type_id', 'grouped'); 
$resource = Mage::getModel('core/resource'); 
$productCollection->getSelect() 
    ->join(array('filter_eav' => $resource->getTableName('catalog/product_index_eav')), 
     "e.entity_id = filter_eav.entity_id AND filter_eav.attribute_id = {$attributeId} AND value = {$valueId}", 
     array('')); 

最初该表在Mage_Catalog_Model_Resource_Layer_Filter_Attribute功能applyFilterToCollection使用。但它需要过滤器对象作为参数。

相关问题