Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
- <type name="MagentoFrameworkViewElementUiComponentDataProviderReporting">
- <plugin name="products_grid_collection"/>
- </type>
- <type name="ProductGrid">
- <arguments>
- <argument name="frontUrlModel" xsi:type="object" shared="false">MagentoFrameworkUrl</argument>
- </arguments>
- </type>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- <module name="SouqTime_ProductViewToProductGrid" setup_version="1.0.0">
- </module>
- <?php
- namespace SouqTimeProductViewToProductGridUiComponentColumns;
- use MagentoCatalogApiProductRepositoryInterface;
- use MagentoFrameworkViewElementUiComponentContextInterface;
- use MagentoFrameworkViewElementUiComponentFactory;
- use MagentoUiComponentListingColumnsColumn;
- use MagentoFrameworkApiSearchCriteriaBuilder;
- use MagentoCatalogModelProductFactory;
- class ProductGrid extends Column
- {
- protected $_product;
- protected $_coreRegistry = null;
- protected $_emulation;
- protected $_productRepository;
- protected $_searchCriteria;
- protected $_productFactory;
- public function __construct(
- ContextInterface $context,
- UiComponentFactory $uiComponentFactory,
- ProductRepositoryInterface $productRepository,
- MagentoFrameworkRegistry $registry,
- MagentoCatalogModelProduct $product,
- SearchCriteriaBuilder $criteria,
- ProductFactory $productFactory,
- MagentoFrameworkUrlInterface $frontUrlModel,
- MagentoStoreModelAppEmulation $emulation,
- array $components = [], array $data = []
- )
- {
- $this->_productRepository = $productRepository;
- $this->_searchCriteria = $criteria;
- $this->_productFactory = $productFactory;
- $this->_coreRegistry = $registry;
- $this->_product = $product;
- $this->_emulation = $emulation;
- parent::__construct($context, $uiComponentFactory, $components, $data);
- }
- public function _geddtProductUrl()
- {
- $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
- $storeid = $storeManager->getStore()->getStoreId();
- $storecode = $storeManager->getStore()->getCode();
- if (!$storecode) {
- $this->_emulation->startEnvironmentEmulation(null, MagentoFrameworkAppArea::AREA_FRONTEND, true);
- $productUrl = $this->_product->loadByAttribute('entity_id', $this->_coreRegistry->registry('product')->getId())->getProductUrl();
- $this->_emulation->stopEnvironmentEmulation();
- return $productUrl;
- } else {
- return $this->_product
- ->loadByAttribute('entity_id', $this->_coreRegistry->registry('product')->getId()
- )->setStoreId($store)->getUrlInStore();
- }
- }
- public function prepareDataSource(array $dataSource)
- {
- if (isset($dataSource['data']['items'])) {
- foreach ($dataSource['data']['items'] as & $item) {
- $prd = $this->_productRepository->get($item["entity_id"]);
- $prd_id = $prd->getEntityId();
- $collection = $this->_productFactory->create()->getCollection();
- $data = $collection->getFirstItem();
- $url = sprintf("window.open('%s')", $this->_getProductUrl());
- $item[$this->getData('preview')] = $productUrl;
- }
- }
- return $dataSource;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="
- urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
- <columns name="product_columns">
- <column name="preview" class="SouqTimeProductViewToProductGridUiComponentColumnsProductGrid">
- <argument name="data" xsi:type="array">
- <item name="config" xsi:type="array">
- <item name="filter" xsi:type="string">text</item>
- <item name="label" xsi:type="string" translate="true">View</item>
- </item>
- </argument>
- </column>
- </columns>
- </listing>
Add Comment
Please, Sign In to add comment