when I am displaying product name through product id Requested product, doesn't exist an error is coming
<?php
namespace Magneto\PopupQuestion\Ui\Component\Listing\Column;
use \Magento\Catalog\Api\ProductRepositoryInterface;
use \Magento\Framework\View\Element\UiComponent\ContextInterface;
use \Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
class Products extends Column
{
protected $_ProductRepository;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
ProductRepositoryInterface $ProductRepository,
array $components = [],
array $data = []){
$this->_ProductRepository = $ProductRepository;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource){
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
$productArr = [];
$product = $this->_ProductRepository->get($items["entity_id"]);
foreach ($product->getAllVisibleItems() as $item) {
$productArr[] = $item->getName(); //to get product name
}
$items['products'] = implode(' - ', $productArr);
unset($productArr);
}
}
return $dataSource;
}
}