5

I am displaying a custom product collection in a block that extends the category block.

I have overriden catalog_category_view in my custom module. The custom filter yields renders proper collection in the category page, but the layered navigation and the toolbar doesnot render the proper collection.

catalog_category_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Namespace\Module\Block\Category\Form" name="custom_category_collection" before=
                "-" template="category/filter.phtml">
            </block>
        </referenceContainer>
    </body>
</page>

app/code/namespace/module/Block/Category/Form.php

<?php 
namespace Namespace\Module\Block\Category;

class Form extends \Magento\Framework\View\Element\Template 
{
    protected $_catalogLayer;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\Layer\Resolver $layerResolver,
        array $data = []
    ) {
        $this->_catalogLayer = $layerResolver->get();
        parent::__construct($context, $data);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $collection = $this->_catalogLayer->getProductCollection();

        $select = $collection->getSelect();
        $select->where("e.entity_id = 18");
        return $this;
    } 
}

Strange thing is, i noticed that the toolbar and layered navigation worked well with the custom collection when the module CatalogSearch was disabled. But otherwise, it doesnt work.

Can anyone suggest a solution. Thanks.

3
  • 1
    did you get the solution for it ? Please share your answer. Sep 21, 2016 at 6:40
  • @Manashvi birla did you get the solution for it ? i have the same problem
    – omelandr
    Jan 14, 2017 at 18:01
  • i dnt have any solution yet.! Jan 16, 2017 at 5:03

1 Answer 1

0

Please use getSize() function on product collection after your filters

$collection->getSize();

It calculates all mandatory data for layered and toolbar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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