2012-02-25 7 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に使用されています。しかし、それはparamとしてフィルタオブジェクトを必要とします。

関連する問題