Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Replace $this->getLoadedProductCollection() in Search with own collection
 
illo_sdrawkcab
Member
 
Total Posts:  63
Joined:  2008-10-23
 

Good morning at all,

i modified the default search template to search by selected root-categories. This works fine so far. Unfortunately i cant say the toolbar that not all of the products in the collection are shown.
For example category 1 is selected with the search term “bike”. In category 1 are 5 bikes and in category 2 are 3.
The result shows the 5 bikes from category 1 but the toolbar says: items 1 to 8 of 8 total.

To solve this problem i need to remove not shown products from the ‘whereeveritcomesfrom’ this->getCollection or even build a new object with my selected products.

hope someone has some methods for me that i can use

for better understanding here my code from the list-template:

<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php 
if(!$_productCollection->count()): ?>
<div class="note-msg">
    
<?php echo $this->__('There are no products matching the selection.'?>
</div>
<?php else: ?>

<?php 
echo $this->getToolbarHtml() ?>
<?php 
// List mode ?>
<?php $isMatch false?>
<?php $ctn_show 
0?>
<?php $listetProducts 
''?>
<?php 
if($this->getMode()!='grid'): ?>
<?php $_iterator 
0?>
<div class="listing-type-list catalog-listing">
    
<?php foreach($_GET as $key=>$searchCrits): ?> 
            <?php 
if($searchCrits=='on'): ?>
                <?php 
foreach( $storeCats $this->helper('catalog/category')->getStoreCategories() as $_category):?>
                    <?php 
if($_category->getId() == $key): ?>
                    <?php $getRecursiveCategories 
$this->getRecursiveCategories($_category); ?>
                    <?php $getRecursiveCategoriesArray 
array_unique(explode(',',substr($getRecursiveCategories,1))); ?>
                    <?php 
foreach($getRecursiveCategoriesArray as $recCatId): ?>
                    <?php $cur_category 
Mage::getModel('catalog/category')->load($recCatId); ?>
                        <?php $_products 
Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cur_category); ?>
                        <?php $_products
->load(); ?>
                        
                        <?php 
foreach ( $_products as $keyLi=>$product ): ?>
                            <?php 
foreach ($_productCollection as $keyOr=>$_product): ?>
                                <?php 
if($keyLi == $keyOr && strstr($listetProducts,$keyOr.',')==false): ?>
                                <?php 
/* save ids to exclude double listed */ ?>
                                <?php $listetProducts 
.= $keyOr.','?>
                                <?php $isMatch 
true?>
                                    
                                    
<div class="listing-item">
                                                                         <!-- 
HERE COMES THE STANDARD CODE TO DISPLAY LIST ( no more characters :) ) -->
                                    </
div>
                                
<?php 
                                   
# here my tryings to build a new collection
                                    
else: #$_newproductCollection = array_merge($_productCollection[$keyOr]); ?>
                                    
<?php #print_r($_newproductCollection); #print($this->setCollection($_newproductCollection)); ?>
                                
<?php endif; ?>                                
                            <?php 
endforeach; ?>
                         <?php 
endforeach; ?>
                     <?php 
endforeach; ?>
                <?php 
endif; ?>
            <?php 
endforeach; ?>
        <?php 
endif; ?>
    <?php 
endforeach; ?>
    <?php $_realShownProd 
$ctn_show?>
</div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
illo_sdrawkcab
Member
 
Total Posts:  63
Joined:  2008-10-23
 

I think i get closer to solve this problem.
Now i added this line:

<?php $_productCollection $_productCollection->addCategoryFilter($cur_category,false,true); ?>

after the 4. foreach.

So i hoped that the collection shows only products from the category in the filter.
But somehow it throws an error.
If this were working is that collectionfilter automatically included in the toolbar?
And how can i remove this error ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top