1

I would like to show products in all categories only if their tier prices were set. I had some success with a plugin for the Layer Model (with afterGetProductCollection). I just added join to the select (joined the ...tier_price table).

One problem remains: the product count and pagination is wrong (as if the filters weren't applied) and no matter what I try, I am not able to find a way to apply a central filter condition.

0

Just in case anybody ever comes across such problems, where you filter the collection and the count is off... There was a problem in at least up to 2.1.9. When you use a GROUP BY in your statement, it doesn't work as expected. The solution can be found in a (resolved) Magento issue:

In Magento/Catalog/Block/Product/ProductList/Toolbar.php getTotalNum() function must be:

public function getTotalNum() {
return count($this->getCollection()->getAllIds());
}

and in your Magento\Catalog\Model\ResourceModel\Product\Collection override class the getLastPageNumber() function should be:

public function getLastPageNumber()
{
$collectionSize = count($this->getAllIds());
if (0 === $collectionSize) {
return 1;
} elseif ($this->_pageSize) {
return ceil($collectionSize / $this->_pageSize);
} else {
return 1;
}
}

Also see: https://github.com/magento/magento2/issues/4767

  • That you shouldn't edit core files but use a Rewrite or the like, is implied ;-) – Jan Brinkmann Feb 15 '18 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.