Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Extending Tags Module without Breaking Search
 
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)
 
Thread Tools Search this Thread
  #11  
Old 07-23-2018, 07:41 AM
 
xgarb xgarb is offline
 

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

Default Re: Extending Tags Module without Breaking Search

Hi,

This is my model:

PHP Code:
abstract class Product extends \XLite\Model\Repo\Product implements \XLite\Base\IDecorator
{
    const 
P_MORE_THAN_1000 'moreThan1000';
    const 
P_HAS_TAGS 'hasTags';
    
    protected function 
getHandlingSearchParams()
    {
        
$params parent::getHandlingSearchParams();

        
$params[] = self::P_HAS_TAGS;
        
$params[] = self::P_MORE_THAN_1000;
                        
        return 
$params;
    }    
    

    protected function 
prepareCndHasTags(\Doctrine\ORM\QueryBuilder $queryBuilder$value)
    {
        
$result $queryBuilder;    
    
        
$path 'approvals/atex-mcerts'//$value;
        
$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;
    }
    

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

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



This is my ItemsList:

PHP Code:
class Result extends \XLite\View\ItemsList\Product\Customer\Search
{
    use \
XLite\View\ItemsList\Product\Customer\DefaultSortByTrait;
    
    const 
PARAM_BY_TAG               'by_tag';    
    
    protected function 
defineRepositoryName()
    {
        return 
'\XLite\Model\Product';
    }

    public function 
__construct(array $params = array())
    {
        
parent::__construct($params);
    }

    protected function 
getHead()
    {
        return 
null;
    }
    
    public static function 
getSearchParams()
    {
        return array(
            \
XLite\Model\Repo\Product::P_SUBSTRING   => self::PARAM_SUBSTRING,
            \
XLite\Model\Repo\Product::P_INCLUDING   => self::PARAM_INCLUDING,
              \
XLite\Model\Repo\Product::P_BY_TAG      => self::PARAM_BY_TAG,
        );
    }

    protected function 
getSearchCondition()
    {
        
$result parent::getSearchCondition();
        
        foreach (static::
getSearchParams() as $modelParam => $requestParam) {
            
$paramValue $this->getParam($requestParam);
    
            if (
is_string($paramValue)) {
                
$paramValue trim($paramValue);
            }
    
            if (
'' !== $paramValue) {
                
$result->$modelParam $paramValue;
            }
        }


        
$result->{\XLite\Model\Repo\Product::P_ORDER_BY} = $this->getOrderBy();
        
$result->hasTags true;        
        
//$result->moreThan1000 = true;
        
        
return $result;
    }


WIth only the line moreThan1000 gives the correct products and count, just the line hasTags gives the correct products but the count is wrong.

I tried changing the \XLite\View\ItemsList\AItemsList::getItemsCount() method to

PHP Code:
protected function getItemsCount()
    {
        return 
$this->getData($this->getSearchCondition(), true);
    } 


with the same result. I can hard code a value return 55; for example and that works.

I wonder if it's something to do with the getData and true function.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #12  
Old 07-24-2018, 04:26 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is online now
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,388
 

Default Re: Extending Tags Module without Breaking Search

Hi @xgarb,

Can you try to dump the value returned by getSearchCondition() method in getItemsCount() one? Is it any different compared to one returned by getLimitCondition() method in getPageData() one?

They should be the same except search limiting parameters in latter one.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #13  
Old 07-24-2018, 05:29 AM
 
xgarb xgarb is offline
 

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

Default Re: Extending Tags Module without Breaking Search

Like this?

PHP Code:
/**
     * Return number of items in products list
     *
     * @return integer
     */
    
protected function getItemsCount()
    {
        
      \
XLite\Logger::logCustom('andrew''getItemsCount: 'false);
      \
XLite\Logger::logCustom('andrew'$this->getSearchCondition(), false);
        return 
$this->getData($this->getSearchCondition(), true);
        
    } 

PHP Code:
protected function getPageData()
    {
        return 
$this->executeCachedRuntime(function () {
            if (
$this->isExportable()) {
                \
XLite\Core\Session::getInstance()->{static::getConditionCellName()}
                    = 
$this->getExportSearchCondition();
            }

      \
XLite\Logger::logCustom('andrew''getPageData: 'false);
      \
XLite\Logger::logCustom('andrew'$this->getLimitCondition(), false);            
            return 
$this->getData($this->getLimitCondition());
        });
    } 

I get this in the log:...

Quote:
[14:16:13.000000] getItemsCount:
Runtime id: 7d87957dbe53358871b03163711464dc
SAPI: fpm-fcgi; IP: xx.xx.xx.xx
URI: /x5-tags-test/w/flowmeter/approvals/wras-atex-mcerts/
Method: GET

[14:16:13.000000] stdClass::__set_state(array(
'__CLASS__' => 'XLite\\Core\\CommonCell',
'properties' =>
array (
'substring' => 'approvals/wras-atex-mcerts',
'including' => 'any',
'byTag' => NULL,
'orderBy' => 'Array(2)',
'hasTags' => true,
),
))
Quote:
[14:16:13.000000] getPageData:
Runtime id: 7d87957dbe53358871b03163711464dc
SAPI: fpm-fcgi; IP: xx.xx.xx.xx
URI: /x5-tags-test/w/flowmeter/approvals/wras-atex-mcerts/
Method: GET

[14:16:13.000000] stdClass::__set_state(array(
'__CLASS__' => 'XLite\\Core\\CommonCell',
'properties' =>
array (
'substring' => 'approvals/wras-atex-mcerts',
'including' => 'any',
'byTag' => NULL,
'orderBy' => 'Array(2)',
'hasTags' => true,
'limit' => 'Array(2)',
),
))

Full log if it helps: https://pastebin.com/NyyFdhyK
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #14  
Old 07-25-2018, 04:54 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is online now
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,388
 

Default Re: Extending Tags Module without Breaking Search

Yes, like this, but I would also define third parameter of logCustom() method as 'true', so we would see file / line from where getData() is called and be sure that we find the right piece of log to look at.

I would also log what number is returned by getItemsCound() method to check whether this number is indeed what you see in pagination widget.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #15  
Old 07-25-2018, 05:34 AM
 
xgarb xgarb is offline
 

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

Default Re: Extending Tags Module without Breaking Search

New methods:


PHP Code:
protected function getItemsCount()
    {
        
      \
XLite\Logger::logCustom('andrew''getItemsCount: '.$this->getData($this->getSearchCondition(), true), false);
      \
XLite\Logger::logCustom('andrew'$this->getSearchCondition(), true);
        return 
$this->getData($this->getSearchCondition(), true);
        
    } 

PHP Code:
protected function getPageData()
    {
        return 
$this->executeCachedRuntime(function () {
            if (
$this->isExportable()) {
                \
XLite\Core\Session::getInstance()->{static::getConditionCellName()}
                    = 
$this->getExportSearchCondition();
            }

      \
XLite\Logger::logCustom('andrew''getPageData: 'false);
      \
XLite\Logger::logCustom('andrew'$this->getLimitCondition(), true);
            return 
$this->getData($this->getLimitCondition());
        });
    } 

New log: https://pastebin.com/9pZhmMFk

I notice that the items count starts at 182 but later is 2963 (the number shown on the site). The actual number of products is only three.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #16  
Old 07-25-2018, 11:16 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is online now
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,388
 

Default Re: Extending Tags Module without Breaking Search

@xgarb,

I am sorry I cannot say much about what can be the problem judging by these logs only.

getSearchCondition() seems to return proper values, but something does not work right and we need to dig deeper, into search() method and look for the differences between requests for quantity of entities and for actual entities.

If you like I can try to check the problem directly onto your server. For that, please email us at support@x-cart.com with the reference to this forum thread.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:22 PM.

   

 
X-Cart forums © 2001-2018