1

I want to add some condition for pager in order collection.

In Magento\Sales\Block\Order\History.php;

protected function _prepareLayout()
    {
        parent::_prepareLayout();
        if ($this->getOrders()) {
            $pager = $this->getLayout()->createBlock(
                \Magento\Theme\Block\Html\Pager::class,
                'sales.order.history.pager'
            )->setCollection(
                $this->getOrders()
            );
            $this->setChild('pager', $pager);
            $this->getOrders()->load();
        }
        return $this;
    }

I need to add this in pager

$pager = $this->getLayout()->createBlock(
                    \Magento\Theme\Block\Html\Pager::class,
                    'sales.order.history.pager'
                ) ->setAvailableLimit(array(4 => 4))
                  ->setShowPerPage(false)
                  ->setCollection(
                        $this->getOrders()
                    );

So, I have override this block file like

protected function _prepareLayout()
    {
        parent::_prepareLayout();
        if ($this->getOrders()) {
            $pager = $this->getLayout()->createBlock(
                \Magento\Theme\Block\Html\Pager::class,
                'sales.order.history.pager'
            )->setAvailableLimit(array(4 => 4))
                ->setShowPerPage(false)
                ->setCollection(
                $this->getOrders()
            );
            $this->setChild('pager', $pager);
            $this->getOrders()->load();
        }
        return $this;
    }

Exception #0 (Magento\Framework\Exception\LocalizedException): An element with a "sales.order.history.pager" ID already exists.

How to do this.

Thanks.

Your Answer

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

Browse other questions tagged or ask your own question.