View Single Post
  #9  
Old 07-20-2018, 08:45 AM
 
xgarb xgarb is online now
 

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

Default Re: Extending Tags Module without Breaking Search

'K I have it nearly working again. The problem with the memory error turned out to be a problem with a duplicate file with a lowercase letter (Linux server, Windows workstation )

I've also solved the problem with the Error: 'tt' is already defined error with this code

PHP Code:
namespace XLite\Module\xxxx\xxxxProductTags\Model\Repo;

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

    protected function 
prepareCndSubstring(\Doctrine\ORM\QueryBuilder $queryBuilder$value)
    {
        if (
$_GET['target'] == 'search'){        
            
parent::prepareCndSubstring($queryBuilder$value);
        }
    }
        


So the only problem is the items count is counting all products and not just the ones returned.

Using this prepared statement works fine. The items count is correct.

PHP Code:
protected function prepareCndMoreThan1000(\Doctrine\ORM\QueryBuilder $queryBuilder$value)
    {
    
        
$result $queryBuilder;

        if (
$value) {
            
$result
                
->andWhere('p.price > :price')
                ->
setParameter('price'1000);
        }

        return 
$result;
    } 

This prepared statement returns the correct items but the item count is wrong

PHP Code:
protected function prepareCndHasTags(\Doctrine\ORM\QueryBuilder $queryBuilder$value)
    {
        
$result $queryBuilder;    
        
        
$path 'approvals/atex-mcerts'// for test
        
$path = \XLite\Core\Request::getInstance()->substring;
        
$tagsInUrl explode('/'$path);
        
        
$tagsGroupsArray = [];
        while (
count($tagsInUrl)) {
            
$tagsGroupsArray[array_shift($tagsInUrl)] = array_shift($tagsInUrl);
        }
            
        
$result->linkLeft('p.tags''t'); 
        
$result->linkLeft('t.tag_groups''tg');
        
                
$this->addTranslationJoins($queryBuilder't''tt'$this->getTranslationCode());
        
        
$result->addGroupBy('p.id');
        
        
        foreach (
$tagsGroupsArray as $key => $val) {
            
$inString str_replace("-""','"$val);
            
$result->andHaving("SUM(CASE WHEN tt.name IN ('".$inString."') AND tg.group_name = '".$key."' THEN 1 ELSE 0 END  ) > 0");
        }
    
        return 
$result;
    } 

Is there some code in the statement that prevents the count function working?
__________________
Core version: 5.5.xx
Reply With Quote