4

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.

  • 1
    did you get the solution for it ? Please share your answer. – Ankur Bhadania Sep 21 '16 at 6:40
  • @Manashvi birla did you get the solution for it ? i have the same problem – omelandr Jan 14 '17 at 18:01
  • i dnt have any solution yet.! – Manashvi Birla Jan 16 '17 at 5:03
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, privacy policy and cookie policy

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