1

i got this error while load new product collection in my custom cms page

protected function _prepareLayout()
   {
      parent::_prepareLayout();
       $this->pageConfig->getTitle()->set(__('Best Seller'));

       if ($this->getCollection()) {
            $pager = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager','newproduct.history.pager')->setAvailableLimit(array(5=>5,10=>10,15=>15,20=>20));
            $pager->setLimit(5)->setShowPerPage(true);
            $pager->setCollection($this->getCollection());
            $this->setChild('pager', $pager);
            $this->getCollection()->load();
        }
        return $this;
   }
   public function getPagerHtml(){
        return $this->getChildHtml('pager');
    }

    public function getCollection(){
      $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
      $pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest()->getParam('limit') : 100;
        $collection = $this->_productsFactory->create()
        ->addAttributeToSelect('*')
        ->setOrder('entity_id','desc')
        ->setPageSize(20)
        ->setPageSize($pageSize)->setCurPage($page);
        return $collection;
   }

Error

Error filtering template: Element with ID 'newproduct.history.pager' already exists.

How to fix this issue

8
  • Try change name of created block to any another, it is should help. Commented Nov 10, 2017 at 9:41
  • Sorry i am not getting
    – Magento 2
    Commented Nov 10, 2017 at 10:27
  • i tried to change this name newproduct.history.pager but still error only
    – Magento 2
    Commented Nov 10, 2017 at 10:33
  • Text of error is changed? Commented Nov 10, 2017 at 10:56
  • Yes it changed...
    – Magento 2
    Commented Nov 10, 2017 at 11:18

1 Answer 1

0

I solved this issue by following code,

by changing sales.order.history.pager to 'sales.order.history.custompager

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

Hope it helps to someone.

1
  • what are sales.order.history.custompager? Commented Sep 30, 2023 at 23:04

Your Answer

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

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