Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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_PopupQuestionProducts</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>
- <?php
- namespace MagnetoPopupQuestionUiComponentListingColumn;
- use MagentoCatalogApiProductRepositoryInterface;
- use MagentoFrameworkViewElementUiComponentContextInterface;
- use MagentoFrameworkViewElementUiComponentFactory;
- use MagentoUiComponentListingColumnsColumn;
- 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;
- }
- }
- <?php
- namespace MagentoPopupQuestionUiComponentListingColumn
- use MagentoCatalogApiProductRepositoryInterface;
- use MagentoFrameworkViewElementUiComponentContextInterface;
- use MagentoFrameworkViewElementUiComponentFactory;
- use MagentoUiComponentListingColumnsColumn;
- 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;
- }
- }
Add Comment
Please, Sign In to add comment