2012-02-25 2 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_AttributeapplyFilterToCollection 기능에 사용된다. 그러나 필터 객체를 param으로 필요로합니다.

관련 문제