Skip to content

Magento 2.4 admin sales order grid spinner loading forever

Scenario: new Magento 2.4.5 environment with sample data
I added my custom plugin by which I add to sales order view three custom columns. All seems to work but when I go to sales/order in admin panel I get this error:

The entity that was requested doesn't exist. Verify the entity and try again

app/code/MyModule/view/adminhtml/ui_component/sales_order_grid.xml

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <listingToolbar name="listing_top"/>  <!-- https://github.com/magento/magento2/issues/5408 -->
    <columns name="sales_order_columns">
        
        <column name="create_invoice" class="VendorAppUiComponentListingColumnColumnCreateInvoice">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Crea fattura</item>
                    <item name="sortOrder" xsi:type="number">600</item>
                    <item name="component" xsi:type="string">Vendor_App/js/grid/columns/create_invoice</item>
                    <item name="sortable" xsi:type="boolean">false</item>
                    <item name="visible" xsi:type="boolean">true</item>
                </item>
            </argument>
        </column>
      
[...] // other two custom columns  
        
    </columns>
</listing>

here below I added try/catch and recompiled

Vendor/App/Ui/Component/Listing/Column/columnCreateInvoice.php

<?php

namespace VendorAppUiComponentListingColumn;
 
use MagentoFrameworkUrlInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoSalesApiOrderRepositoryInterface;

class ColumnCreateInvoice extends Column
{
    protected $objectManager;
    protected $orderRepository;
    
    public function __construct
    (
        ContextInterface $context,
        MagentoFrameworkObjectManagerInterface $objectManager,
        UiComponentFactory $uiComponentFactory,
        OrderRepositoryInterface $orderRepository,
        VendorAppHelperData $helper,
        array $components = [],
        array $data = []
    )
    {
        $this->objectManager = $objectManager;
        $this->orderRepository = $orderRepository;
        $this->helper = $helper;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }
    
    /**
     * Prepare Data Source
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items']))
        { 
            $fieldName = $this->getData('name');
                foreach ($dataSource['data']['items'] as & $item) {
                    try {
                        $order  = $this->orderRepository->get($item['entity_id']);
                        $orderId = $order->getId();
                        $incrementId = $order->getIncrementId();
                    
                        // uso il nuovo metodo per recuperare il numero del documento nel gestionale F24 (registrato nella tabella)
                        $docNumber = $this->helper->getF24DocNumber($incrementId);
                    
                        // Costruisco l'url associato al controller CreateInvoice
                        $baseUrl = $this->objectManager
                        ->get('MagentoStoreModelStoreManagerInterface')
                        ->getStore()
                        ->getBaseUrl();
                        $url = $baseUrl. "vendor/index/createinvoice/id/". $incrementId;

                        if ($order->isCanceled()) {
                            $item[$fieldName . '_html'] = "<center>Ordine cancellato</center>";
                        } else {
                            $invoicesIds = $this->helper->getInvoicesIds($incrementId);
                            if (!$invoicesIds) {
                                $numberInvoices = 0;
                            } else {
                                $numberInvoices = count($invoicesIds);
                            }
                            if ($order->canInvoice() || ($order->hasInvoices() > $numberInvoices)) {
                                $item[$fieldName . '_html'] = "<center><button class='button' title='Crea la fattura'><span>Crea fattura</span></button></center>";
                            } else {
                                //se lo trovo riporto il riferimento al numero della fattura in F24
                                $item[$fieldName . '_html'] = !empty($docNumber)? "<center><b>Ordine fatturato<br><br> Numero doc: " . $docNumber . "</b>" : "<center><b>Ordine fatturato</b></center>";
                            }
                        }

                        $item[$fieldName . '_orderId'] = $orderId;
                        $item[$fieldName.'_Url'] = $url;
                    } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
                    }

                }
        }
        return $dataSource;
    }
}

After that the Exception disappeared but the spinner is loading forever. Any suggestions?