View Single Post
  #2  
Old 07-11-2018, 01:30 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: Extending Tags Module without Breaking Search

OK.. I've done it like this....

PHP Code:
<?php 

class Product extends \XLite\Model\Repo\Product implements \XLite\Base\IDecorator 


    protected function 
prepareCndSubstring(\Doctrine\ORM\QueryBuilder $queryBuilder$value
    { 
    if (
$_GET['target'] != 'search'){         
        
$tagsGroupsArray // not important but is something like  array('animal' => 'cat-dog','colour' => 'red-blue-green','size' => 'small') 
         
        
$queryBuilder->linkLeft('p.tags''t');  
        
$queryBuilder->linkLeft('t.tag_groups''tg'); 
         
        
$this->addTranslationJoins($queryBuilder't''tt'$this->getTranslationCode()); 
     
        
$queryBuilder->addGroupBy('p.id'); 
         
        foreach (
$tagsGroupsArray as $key => $val) { 
            
$inString str_replace("-""','"$val); 
            
$queryBuilder->andHaving("SUM(CASE WHEN tt.name IN ('".$inString."') AND tg.group_name = '".$key."' THEN 1 ELSE 0 END  ) > 0"); 
        } 
         }
    if (
$_GET['target'] == 'search'){        
    
parent::prepareCndSubstring($queryBuilder$value);
    }            
}

The problem now is that getItemsCount() is counting all the products in the store while the page (the Itemlist) shows the correct result.

I don't know why getData() finds the products based on the tags correctly but it doesn't count the number of results.
__________________
Core version: 5.5.xx
Reply With Quote