I created a module - I put in the code to limit the products by membership to only those products associated with the membership.
After doing so, I noticed the products were fine, but not the categories. So, I put similar code in a module which extends the category. However, the problem I am having is that it doesn't work. I'm still getting all the categories.
I put logging in so I can see that my code is running, but it's not limiting the categories as I would have expected.
It should only be returning categories for which the membership id is 2 in this case, but I am getting them all back.
The PHP code is pretty straight forward:
Code:
namespace XLite\Module\TechAnalysts\ProductsForMemberships\Model\Repo;
/**
* The "category" repo class
*/
abstract class Category extends \XLite\Model\Repo\Category implements \XLite\Base\IDecorator
{
protected function addMembershipCondition(\Doctrine\ORM\QueryBuilder $queryBuilder, $alias = null)
{
if ($this->getMembershipCondition()) {
$alias = $alias ?: $this->getDefaultAlias();
$limit = \XLite\Core\Config::getInstance()->TechAnalysts->ProductsForMemberships->limit_to_membership;
$membership = \XLite\Core\Auth::getInstance()->getMembershipId();
if ($membership) {
$whereClause = 'membership.membership_id = :membershipId';
if ($limit != 'Y') {
$whereClause .= ' OR membership.membership_id IS NULL';
}
\XLite\Logger::logCustom('techanalysts',$whereClause . ': ' . $membership,true);
$queryBuilder->leftJoin($alias . '.memberships', 'membership')
->andWhere($whereClause)
->setParameter('membershipId', \XLite\Core\Auth::getInstance()->getMembershipId());
} else {
$queryBuilder->leftJoin($alias . '.memberships', 'membership')
->andWhere('membership.membership_id IS NULL');
}
}
}
}
I'm not sure what's causing my problems at this point nor where to go to find more information.
I did notice that the Category is using $queryBuilder->leftJoin whereas the Product is using $queryBuilder->linkLeft. I'm not sure if that's part of the problem or not.