Thanks for the tips. This is what I have so far...
Controller
PHP Code:
namespace XLite\Module\XCExample\SearchRepoDemo\Controller\Customer;
class ItemsListDemo extends \XLite\Controller\Customer\ACustomer
{
public function getTitle()
{
return 'Hello World';
}
}
Repo
PHP Code:
namespace XLite\Module\XCExample\SearchRepoDemo\Model\Repo;
abstract class Product extends \XLite\Model\Repo\Product implements \XLite\Base\IDecorator
{
const P_MORE_THAN_10 = 'moreThan10';
const P_HAS_TAGS = 'hasTags';
protected function getHandlingSearchParams()
{
$params = parent::getHandlingSearchParams();
$params[] = self::P_MORE_THAN_10;
$params[] = self::P_HAS_TAGS;
return $params;
}
protected function prepareCndHasTags(\Doctrine\ORM\QueryBuilder $queryBuilder)
{
$result = $queryBuilder;
$path = 'approvals/atex-mcerts'; //$value;
$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($result, '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 prepareCndMoreThan10(\Doctrine\ORM\QueryBuilder $queryBuilder, $value)
{
$result = $queryBuilder;
if ($value) {
$result
->andWhere('p.price > :price')
->setParameter('price', 10.00);
}
return $result;
}
}
Tag Model
PHP Code:
namespace XLite\Module\XCExample\SearchRepoDemo\Model;
class Tag extends \XLite\Module\XC\ProductTags\Model\Tag implements \XLite\Base\IDecorator
{
/**
*
* @var \XLite\Module\XCExample\SearchRepoDemo\Model\TagGroup
* @ManyToOne (targetEntity="XLite\Module\XCExample\SearchRepoDemo\Model\TagGroup", inversedBy="tags")
* @JoinColumn (name="group_id", referencedColumnName="id")
*/
protected $tag_groups;
}
Tag Group Model
PHP Code:
namespace XLite\Module\XCExample\SearchRepoDemo\Model;
/**
* The "TagGroup" model class
*
* @Entity
* @Table (name="tag_groups")
*/
class TagGroup extends \XLite\Model\AEntity
{
/**
* Unique ID
*
* @var integer
*
* @Id
* @GeneratedValue (strategy="AUTO")
* @Column (type="integer", options={ "unsigned": true })
*/
protected $id;
/**
* @Column (type="string", length=255)
*/
protected $group_name;
/**
* Returns id
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set text
*
* @param string $value Value
*
* @return void
*/
public function setText($value)
{
$this->text = $value;
}
/**
* Returns text
*
* @return string
*/
public function getText()
{
return $this->text;
}
}
ItemsList
PHP Code:
namespace XLite\Module\XCExample\SearchRepoDemo\View\ItemsList\Customer;
class ItemsListDemo extends \XLite\View\ItemsList\Product\Customer\Search
{
const SORT_BY_MODE_PRICE = 'p.price';
protected function defineRepositoryName()
{
return '\XLite\Model\Product';
}
public static function getAllowedTargets()
{
return array_merge(parent::getAllowedTargets(), array('items_list_demo'));
}
public function __construct(array $params = array())
{
$this->sortByModes += array(
static::SORT_BY_MODE_PRICE => 'Price',
);
parent::__construct($params);
}
protected function getSortByModeDefault()
{
return static::SORT_BY_MODE_PRICE;
}
protected function getSearchCondition()
{
$result = parent::getSearchCondition();
$result->{\XLite\Model\Repo\Product::P_ORDER_BY} = $this->getOrderBy();
$result->moreThan10 = true;
$result->hasTags = true;
return $result;
}
}
I have the following error:
[Semantical Error] line 0, col 314 near 'tt WHERE p.enabled': Error: 'tt' is already defined.
from this code
PHP Code:
protected function prepareCndSubstring(\Doctrine\ORM\QueryBuilder $queryBuilder, $value)
{
$queryBuilder->linkLeft('p.tags', 't');
$this->addTranslationJoins($queryBuilder, 't', 'tt', $this->getTranslationCode());
parent::prepareCndSubstring($queryBuilder, $value);
}
in this file: XLite\Module\XC\ProductTags\Model\Repo\Product
I'm not sure what to do to stop the querybuilder adding the code in ProductTags repo?
T