1

We have migrated orders data but old orders we have sales_order_grid & sales_order order status is Delivered but in M2 we are considering status as delivered

We would like to adjust the order grid column to use both formats. please adviseenter image description here

1 Answer 1

0

I got the answer to this question here are the steps which will help for the stack users if require

  1. Create app/code/Magento/Stackexchange/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">    
    <columns name="sales_order_columns">
        <column name="status" class="Magento\Stackexchange\Ui\Component\Listing\Column\Status">
            <settings>
                <filter>select</filter>
                <options class="Magento\Sales\Ui\Component\Listing\Column\Status\Options"/>
                <dataType>select</dataType>
                <label translate="true">Status</label>
            </settings>
        </column>  
    </columns>
    

  2. Create app/code/Magento/Stackexchange/Ui/Component/Listing/Column/Status.php

    <?php
       namespace Magento\Stackexchange\Ui\Component\Listing\Column;
    
      use Magento\Ui\Component\Listing\Columns\Column;
      use Magento\Framework\View\Element\UiComponent\ContextInterface;
     use Magento\Framework\View\Element\UiComponentFactory;
     use Magento\Sales\Api\OrderRepositoryInterface;
    
    class Status extends Column
    
    
     {
       /**
     * @var OrderRepositoryInterface
     */
    private $orderRepository;
    
    /**
     * status constructor.
     *
     * @param ContextInterface $context
     * @param UiComponentFactory $uiComponentFactory
     * @param OrderRepositoryInterface $orderRepository
     * @param array $components
     * @param array $data
     */
    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        OrderRepositoryInterface $orderRepository,
        array $components = [],
        array $data = []
    ) {
        $this->orderRepository = $orderRepository;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }
    
    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                $order  = $this->orderRepository->get($item["entity_id"]);
                $isStatus = $order->getData("status");
                if($isStatus == 'Delivered') {
                    $isStatus='delivered';
                } 
                $item[$this->getData('name')] = $isStatus;
            }
        }
    
        return $dataSource;
    }
    }
    

Your Answer

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

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