SHARE
TWEET

Untitled

a guest Feb 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <field name="entity_id">
  2.         <argument name="data" xsi:type="array">
  3.             <item name="config" xsi:type="array">
  4.                 <item name="dataType" xsi:type="string">text</item>
  5.                 <item name="label" translate="true" xsi:type="string">product name</item>
  6.                 <item name="formElement" xsi:type="string">input</item>
  7.                 <item name="source" xsi:type="string">Product</item>
  8.                 <item name="disabled" xsi:type="boolean">true</item>
  9.                 <item name="class" xsi:type="string">Magneto_PopupQuestionProducts</item>
  10.                 <item name="sortOrder" xsi:type="number">30</item>
  11.                 <item name="dataScope" xsi:type="string">entity_id</item>
  12.                 <item name="validation" xsi:type="array">
  13.                     <item name="required-entry" xsi:type="boolean">false</item>
  14.                 </item>
  15.             </item>
  16.         </argument>
  17.     </field>
  18.    
  19. <?php
  20. namespace MagnetoPopupQuestionUiComponentListingColumn;
  21.  
  22. use MagentoCatalogApiProductRepositoryInterface;
  23. use MagentoFrameworkViewElementUiComponentContextInterface;
  24. use MagentoFrameworkViewElementUiComponentFactory;
  25. use MagentoUiComponentListingColumnsColumn;
  26.  
  27. class Products extends Column
  28. {
  29.     protected $_ProductRepository;
  30.  
  31.     public function __construct(
  32.         ContextInterface $context,
  33.         UiComponentFactory $uiComponentFactory,
  34.         ProductRepositoryInterface $ProductRepository,
  35.         array $components = [],
  36.         array $data = []
  37.     ) {
  38.         $this->_ProductRepository = $ProductRepository;
  39.         parent::__construct($context, $uiComponentFactory, $components, $data);
  40.     }
  41.  
  42.     public function prepareDataSource(array $dataSource)
  43.     {
  44.         if (isset($dataSource['data']['items'])) {
  45.             foreach ($dataSource['data']['items'] as $key => $items) {
  46.                 $product = $this->_ProductRepository->getById($items["entity_id"]);
  47.                 $dataSource['data']['items'][$key]['entity_id'] = $product->getName(); //to get product name
  48.             }
  49.         }
  50.         return $dataSource;
  51.     }
  52. }
  53.    
  54. <?php
  55. namespace MagentoPopupQuestionUiComponentListingColumn
  56.  
  57. use MagentoCatalogApiProductRepositoryInterface;
  58. use MagentoFrameworkViewElementUiComponentContextInterface;
  59. use MagentoFrameworkViewElementUiComponentFactory;
  60. use MagentoUiComponentListingColumnsColumn;
  61.  
  62. class Products extends Column
  63. {
  64.     protected $_ProductRepository;
  65.  
  66.     public function __construct(
  67.         ContextInterface $context,
  68.         UiComponentFactory $uiComponentFactory,
  69.         ProductRepositoryInterface $ProductRepository,
  70.         array $components = [],
  71.         array $data = []
  72.     ) {
  73.         $this->_ProductRepository = $ProductRepository;
  74.         parent::__construct($context, $uiComponentFactory, $components, $data);
  75.     }
  76.  
  77.     public function prepareDataSource(array $dataSource)
  78.     {
  79.         $fieldName = $this->getData('name');
  80.  
  81.         if (isset($dataSource['data']['items'])) {
  82.             foreach ($dataSource['data']['items'] as &$item) {
  83.                 $product = $this->_ProductRepository->getById($item["entity_id"]);
  84.                  $item[$fieldName] = $product->getName();
  85.             }
  86.         }
  87.         return $dataSource;
  88.     }
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top