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.