1

I add a custom column to order grid but after that filter not working correctly and throws an error every time:

A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later.

My code of column is:

<?php

namespace Magento\Sales\Ui\Component\Listing\Column;

use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;

/**
 * Class ProductName
 */
class ProductName extends Column
{

    protected $productFactory;
    protected $orderFactory;

    /**
     * Constructor
     *
     * @param ContextInterface $context
     * @param UiComponentFactory $uiComponentFactory
     * @param array $components
     * @param array $data
     */
    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        \Magento\Catalog\Model\ProductFactory $productFactory,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        array $components = [],
        array $data = []
    ) {
        $this->productFactory = $productFactory;
        $this->orderFactory = $orderFactory;
        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) {
                # $item[increment_id] is the order id
                $order = $this->orderFactory->create()->loadByIncrementId((int)$item['increment_id']);
                $orderItems = $order->getAllItems(); # get all items 
                $item[$this->getData('name')] = '';
                foreach ($orderItems as $index => $oi) {
                    $product = $this->productFactory->create()->load($oi->getProductId());
                    $item[$this->getData('name')] .= $product->getName();
                    $item[$this->getData('name')] .= (sizeof($orderItems) > $index+1) ? ", " : "";
                }
            }
        }

        return $dataSource;
    }
}
  • what error??? Be more specific. – padhiyar gaurang Oct 12 '17 at 12:27
  • Whenever i try to search from search box or filters it gives error popup that "Something went wrong" and then no data loads in grid. – Bunny Oct 12 '17 at 12:30
  • check you var/report folder, may you find something there. Also, update your grid code so I can see to help you. – padhiyar gaurang Oct 12 '17 at 12:31
  • I have updated my code of custom column – Bunny Oct 12 '17 at 12:37
  • You want column products items of the order? right? – padhiyar gaurang Oct 12 '17 at 12:41

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.