Guest User

Untitled

a guest
Oct 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  3. <type name="MagentoFrameworkViewElementUiComponentDataProviderReporting">
  4. <plugin name="products_grid_collection"/>
  5. </type>
  6. <type name="ProductGrid">
  7. <arguments>
  8. <argument name="frontUrlModel" xsi:type="object" shared="false">MagentoFrameworkUrl</argument>
  9. </arguments>
  10. </type>
  11.  
  12. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13. xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  14. <module name="SouqTime_ProductViewToProductGrid" setup_version="1.0.0">
  15. </module>
  16.  
  17. <?php
  18. namespace SouqTimeProductViewToProductGridUiComponentColumns;
  19. use MagentoCatalogApiProductRepositoryInterface;
  20. use MagentoFrameworkViewElementUiComponentContextInterface;
  21. use MagentoFrameworkViewElementUiComponentFactory;
  22. use MagentoUiComponentListingColumnsColumn;
  23. use MagentoFrameworkApiSearchCriteriaBuilder;
  24. use MagentoCatalogModelProductFactory;
  25.  
  26. class ProductGrid extends Column
  27. {
  28. protected $_product;
  29. protected $_coreRegistry = null;
  30. protected $_emulation;
  31. protected $_productRepository;
  32. protected $_searchCriteria;
  33. protected $_productFactory;
  34.  
  35.  
  36. public function __construct(
  37. ContextInterface $context,
  38. UiComponentFactory $uiComponentFactory,
  39. ProductRepositoryInterface $productRepository,
  40. MagentoFrameworkRegistry $registry,
  41. MagentoCatalogModelProduct $product,
  42. SearchCriteriaBuilder $criteria,
  43. ProductFactory $productFactory,
  44. MagentoFrameworkUrlInterface $frontUrlModel,
  45. MagentoStoreModelAppEmulation $emulation,
  46. array $components = [], array $data = []
  47. )
  48. {
  49. $this->_productRepository = $productRepository;
  50. $this->_searchCriteria = $criteria;
  51. $this->_productFactory = $productFactory;
  52. $this->_coreRegistry = $registry;
  53. $this->_product = $product;
  54. $this->_emulation = $emulation;
  55. parent::__construct($context, $uiComponentFactory, $components, $data);
  56. }
  57.  
  58. public function _geddtProductUrl()
  59. {
  60. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  61. $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
  62. $storeid = $storeManager->getStore()->getStoreId();
  63. $storecode = $storeManager->getStore()->getCode();
  64.  
  65. if (!$storecode) {
  66. $this->_emulation->startEnvironmentEmulation(null, MagentoFrameworkAppArea::AREA_FRONTEND, true);
  67. $productUrl = $this->_product->loadByAttribute('entity_id', $this->_coreRegistry->registry('product')->getId())->getProductUrl();
  68. $this->_emulation->stopEnvironmentEmulation();
  69.  
  70. return $productUrl;
  71. } else {
  72. return $this->_product
  73. ->loadByAttribute('entity_id', $this->_coreRegistry->registry('product')->getId()
  74. )->setStoreId($store)->getUrlInStore();
  75. }
  76.  
  77.  
  78. }
  79.  
  80. public function prepareDataSource(array $dataSource)
  81. {
  82. if (isset($dataSource['data']['items'])) {
  83. foreach ($dataSource['data']['items'] as & $item) {
  84.  
  85. $prd = $this->_productRepository->get($item["entity_id"]);
  86.  
  87. $prd_id = $prd->getEntityId();
  88.  
  89. $collection = $this->_productFactory->create()->getCollection();
  90.  
  91. $data = $collection->getFirstItem();
  92.  
  93. $url = sprintf("window.open('%s')", $this->_getProductUrl());
  94.  
  95. $item[$this->getData('preview')] = $productUrl;
  96.  
  97.  
  98. }
  99.  
  100. }
  101.  
  102. return $dataSource;
  103. }
  104.  
  105.  
  106. }
  107.  
  108. <?xml version="1.0" encoding="UTF-8"?>
  109. <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  110. xsi:noNamespaceSchemaLocation="
  111. urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  112. <columns name="product_columns">
  113. <column name="preview" class="SouqTimeProductViewToProductGridUiComponentColumnsProductGrid">
  114. <argument name="data" xsi:type="array">
  115. <item name="config" xsi:type="array">
  116. <item name="filter" xsi:type="string">text</item>
  117. <item name="label" xsi:type="string" translate="true">View</item>
  118. </item>
  119. </argument>
  120. </column>
  121. </columns>
  122. </listing>
Add Comment
Please, Sign In to add comment