We are working on Magento 2.2.5, override the \Magento\Sales\Block\Order\Items class method _prepareLayout but it is not working showing error.

File : etc\module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Kh_Test" setup_version="1.0.0">
            <module name="Magento_Sales"/>

File : etc\di.xml

<preference for="Magento\Sales\Block\Order\Items" type="Kh\Test\Block\Order\Items" /> 

File : Kh\Test\Block\Order;


namespace Kh\Test\Block\Order;

class Items extends \Magento\Sales\Block\Order\Items

    protected function _prepareLayout()
        $this->itemsPerPage = $this->_scopeConfig->getValue('sales/orders/items_per_page');

        $this->itemCollection = $this->itemCollectionFactory->create();

        /** @var \Magento\Theme\Block\Html\Pager $pagerBlock */
        $pagerBlock = $this->getChildBlock('sales_order_item_pager');
        if ($pagerBlock) {
            //here pager updates collection parameters

        return parent::_prepareLayout();



1 exception(s): Exception #0 (Exception): Notice: Undefined property: Qfix\Gst\Block\Order\Items::$itemCollectionFactory in .../app/code/Kh/Test/Block/Order/Items.php on line 12

  • add constructor with this parent::__construct($context, $registry, $data, $itemCollectionFactory); – Prathap Gunasekaran Mar 8 at 11:20
  • public function __construct() { parent::__construct($context, $registry, $data, $itemCollectionFactory); } I tried but it shows me This page isn’t working – Kishor Hase Mar 8 at 11:33
  • Please do inject arguments like extending class. Add as similar to the block which you're extending and replace the parent with this one. – Prathap Gunasekaran Mar 8 at 11:36
  • Thank your reply, I tried same way and compile i got error Kh\Test\Block\Order\Items Incompatible argument type: Required type: \Magento\Framework\Registry. Actual type: array; File: ...../app/code/Kh/Test/Block/Order/Items.php – Kishor Hase Mar 8 at 12:04

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.