Skip to content

Exception #0 (MagentoFrameworkExceptionLocalizedException): Invalid method VendorModulenameBlockSalesOrderItems:::isPagerDisplayed

I am going to add some data content in Order Items at the Frontend.I am using Magento 2.4.3

I have given preference in the di.xml file

<preference for="MagentoSalesBlockOrderItems" type="VendorCustomNameSalesBlockOrderItems" />

And Added a plugin :

 <type name="MagentoSalesBlockOrderItems">
        <plugin name="CQC_Serialcodes::getItemHtml" type="VendorModulePluginItems" sortOrder="10"/>
    </type>

I am overriding MagentoSalesBlockOrderItemRendererDefaultRenderer

Block layout

Item.php file :

Path : appcodeVendorModuleBlockSalesOrderItems.php

<?php

/**
 * Sales order view items block
 *
 * @author     Magento Core Team <[email protected]>
 */
namespace VendorModuleBlockSalesOrder;

use VendorModuleHelperData as helper;
use VendorModuleModelSerialcodeFactory as SerialcodeModelFactory;
use MagentoCatalogModelProductRepository as ProductRepositoryModel;
use MagentoFrameworkDataObject;
use MagentoFrameworkEscaper as escaper;
use MagentoFrameworkJsonHelperData as jsonHelper;
use MagentoSalesBlockItemsAbstractItems;
use MagentoSalesModelOrderItemFactory as ItemFactory;
use MagentoSalesModelResourceModelOrderCollectionFactory as CollectionFactory;
use MagentoFrameworkViewElementTemplateContext;
use MagentoFrameworkRegistry;

/**
 * Shipping Items Block
 *
 * @api
 * @since 100.0.2
 */
class Items extends AbstractItems
{
    protected $_productRepository;
    
    //protected $_jsonSerializer;

    /**
     * @var jsonHelper
     */
    protected $jsonHelper;

    protected $itemFactory;

    protected $orderCollection;

    protected $helper;

    protected $serialcodeModelFactory;

    protected $registry;

    /**
     * Escaper
     *
     * @var escaper
     */
    protected $_escaper;

    public function __construct(
        ProductRepositoryModel $productRepository,
        jsonHelper $jsonHelper,
        ItemFactory $itemFactory,
        CollectionFactory $orderCollection,
        SerialcodeModelFactory $serialcodeModelFactory,
        escaper $_escaper,
        Context $context,
        Registry $registry,
        helper $helper,
        array $data = []
    ) {
            $this->_productRepository = $productRepository;
            $this->jsonHelper = $jsonHelper;
            $this->itemFactory =$itemFactory;
            $this->orderCollection=$orderCollection;
            $this->serialcodeModelFactory = $serialcodeModelFactory;
            $this->_escaper=$_escaper;
            $this->helper = $helper;
            $this->registry = $registry;

            parent::__construct($context, $data);
    }

    /**
     * @param DataObject $item
     * @return array|string|string[]
     * @throws MagentoFrameworkExceptionNoSuchEntityException
     */
    public function getItemHtml(DataObject $item)
    {
        $html = "getItemHtml called";
        return $html;
    }
}

Plugin File : appcodeVendorModulePluginItems.php

 <?php

namespace VendorModulePlugin;

use VendorModuleModelSerialcodeFactory as SerialcodeModelFactory;
use MagentoCatalogModelProductRepository as ProductRepositoryModel;
use MagentoFrameworkDataObject;
use MagentoFrameworkViewElementTemplateContext;
use MagentoSalesApiDataOrderInterface;
use MagentoSalesModelOrderItemFactory;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesBlockItemsAbstractItems;
use MagentoFrameworkRegistry;

/**
 *
 */
class Items extends AbstractItems
{
    protected $orderCollection;
    protected $_productRepository;
    protected $serialcodeModelFactory;
    protected $itemFactory;
    protected $order;
    protected $registry;

    public function __construct(
        Context                $context,
        ProductRepositoryModel $productRepository,
        SerialcodeModelFactory        $serialcodeModelFactory,
        Registry $registry,
        CollectionFactory      $orderCollection,
        ItemFactory            $itemFactory,
        OrderInterface         $order,
        array                  $data = []
    )
    {
        $this->_productRepository = $productRepository;
        $this->serialcodeModelFactory = $serialcodeModelFactory;
        $this->orderCollection = $orderCollection;
        $this->itemFactory = $itemFactory;
        $this->order = $order;
        $this->registry = $registry;

        parent::__construct($context, $data);
    }

    /**
     * @param DataObject $item
     * @param array|string|string[] $result
     * @return array|string|string[]
     * @throws MagentoFrameworkExceptionNoSuchEntityException
     */
    public function afterGetItemHtml(DataObject $item, $result)
    {
        $html1 = "after success";
        return $html1;
    }
}

enter image description here

The Output Will be like below screen:
enter image description here