2

I want list all the orders in a single page. how I remove pagination from my orders page in my account dashboard.

  • Are you talking about Sales order history page oR Customer dashboard page? – Amit Bera Feb 20 at 11:14
  • My orders page under customer dashboard.. order sales history – soofz Feb 20 at 11:23
  • @AmitBera on the Customer dashboard page, there is no pagination, it only shows 5 orders under dashboard(My Account), is there any limit on the dashboard orders?I only see 5 orders – summu Feb 21 at 5:49
5

You can remove pagination from using the events layout_generate_blocks_after.

Run an observer on these events and remove the block sales.order.history.pager from layout which is responsible for pagination.

events.xml code:

Location app/code/{Vendor}/{Modulename}/etc/frontend/

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * @author Amit Bera
 * @copyright https://www.amitbera.com/
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> 
    <event name="layout_generate_blocks_after">
        <observer name="remove_pager_block" 
                  instance="{Vendor}\{Modulename}\Observer\RemovePagerFromSalesOrderHistoryObserver"/>
    </event>
</config>

Observer code:

Location app/code/{Vendor}/{Modulename}/Observer/RemovePagerFromSalesOrderHistoryObserver.php

<?php

namespace {Vendor}\{Modulename}\Observer;

use Magento\Framework\Event\ObserverInterface;

class RemovePagerFromSalesOrderHistoryObserver implements ObserverInterface {

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $layout = $observer->getLayout();
        $action = $observer->getFullActionName();
        if ($action !== 'sales_order_history') {
            return;
        }
        $block = $layout->getBlock('sales.order.history');
        if ($block) {
            $layout->unsetElement('sales.order.history.pager');
        }
    }

}

But as layout layout_generate_blocks_after is run later after the limit set so,it showing 10 order on the page.

So, in case, i have used a trick where using a plugin I have tried to reset the page item limit.

Create a plugin on Class Magento\Theme\Block\Html\Pager and using after plugin getLimit() i have modified limit of the current page to 5000;

Plugin di.xml

Location: app/code/{Vendor}/{Modulename}/etc/frontend/di.xml

and code

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Block\Html\Pager">
        <plugin disabled="false" name="reset_limit_sales_order" 
                        sortOrder="10" 
                        type="{Vendor}\{Modulename}\Plugin\Magento\Theme\Block\Html\PagePlugin"/>
    </type>
</config>

PLugin Class

app/code/{Vendor}/{Modulename}/Plugin/Magento/Theme/Block/Html/PagePlugin.php

and code is:

<?php
namespace {Vendor}\{Modulename}\Plugin\Magento\Theme\Block\Html;

class PagePlugin {
    public function afterGetLimit(
     \Magento\Theme\Block\Html\Pager $subject,
      $result      
    )
    {
      if($subject->getNameInLayout() != 'sales.order.history.pager')
      {
          return $result;
      }
      // if sales.order.history.pager then set page limit=5000;
      return 5000;
    }
}
  • Its working but only taking 10 orders. I want to show all order under that customer. Please help. Thanks for your answer. – soofz Feb 20 at 12:16
  • 1
    Sure let me check – Amit Bera Feb 20 at 12:19
  • +1 for the different approach . – Prathap Gunasekaran Feb 21 at 4:38
  • Works fine... Thank you so much for your support @AmitBera – soofz Feb 21 at 5:39

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.