0

hello I want to call the file in form.xml to display the product name but i am getting error class not found

form.xml

    <field name="entity_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" translate="true" xsi:type="string">product name</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">Product</item>
                <item name="disabled" xsi:type="boolean">true</item>
                <item name="class" xsi:type="string">Magneto_PopupQuestion\Products</item>
                <item name="sortOrder" xsi:type="number">30</item>
                <item name="dataScope" xsi:type="string">entity_id</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
            </item>
        </argument>
    </field>

products.php

<?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 $key => $items) {
                $product = $this->_ProductRepository->getById($items["entity_id"]);
                $dataSource['data']['items'][$key]['entity_id'] = $product->getName(); //to get product name
            }
        }
        return $dataSource;
    }
}
2
  • <item name="class" xsi:type="string">Magneto\PopupQuestion\Ui\Component\Listing\Column\Products</item> Feb 18, 2019 at 12:29
  • Class Magento\PopupQuestion\Ui\Component\Listing\Column\Products does not exist is coming Feb 18, 2019 at 12:35

2 Answers 2

0

Magneto_PopupQuestion\Products is not a valid classpath

  • Typo in Magento
  • not the classes namespace
<item name="class" xsi:type="string">Magento\PopupQuestion\Ui\Component\Listing\Column\Products</item>
3
  • same error is coming Class Magento\PopupQuestion\Ui\Component\Listing\Column\Products does not exist Feb 18, 2019 at 12:35
  • did you correct the namespace in your PHP-file? Feb 18, 2019 at 12:35
  • yes no error but product name is not displaying i want to display product name through product id Feb 18, 2019 at 12:37
0

Use Full Class path: <item name="class" xsi:type="string">Magneto\PopupQuestion\Ui\Component\Listing\Column\Products</item>

Also verify either you are using Magento or Magneto.

<?php
namespace Magento\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)
    {
        $fieldName = $this->getData('name');

        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as &$item) {
                $product = $this->_ProductRepository->getById($item["entity_id"]);
                 $item[$fieldName] = $product->getName();
            }
        }
        return $dataSource;
    }
}
15
  • Class Magento\PopupQuestion\Ui\Component\Listing\Column\Products does not exist is coming Feb 18, 2019 at 12:35
  • Then you should write Magento\PopupQuestion\Ui\Component\Listing\Column\Products in class argument you passed in item. also namespace in your Products.php file has typo, Feb 18, 2019 at 12:38
  • no error is coming but the output does not come I want to display the product name through product id i have store product id Feb 18, 2019 at 12:40
  • Check my updated code Feb 18, 2019 at 12:45
  • what changes you have done i cannot see any change Feb 18, 2019 at 13:10

Your Answer

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

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