Nó có thể hữu ích cho bạn.
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
<column name="websites" class="Magento\Catalog\Ui\Component\Listing\Columns\Websites" sortOrder="100">
<settings>
<addField>true</addField>
<options class="Magento\Store\Model\ResourceModel\Website\Collection"/>
<dataType>text</dataType>
<label translate="true">Websites</label>
</settings>
</column>
</columns>
</listing>
Trang web.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Ui\Component\Listing\Columns;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Store\Model\StoreManagerInterface;
/**
* @api
* @since 100.0.2
*/
class Websites extends \Magento\Ui\Component\Listing\Columns\Column
{
/**
* Column name
*/
const NAME = 'websites';
/**
* Store manager
*
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param StoreManagerInterface $storeManager
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
StoreManagerInterface $storeManager,
array $components = [],
array $data = []
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->storeManager = $storeManager;
}
/**
* {@inheritdoc}
* @deprecated 101.0.0
*/
public function prepareDataSource(array $dataSource)
{
$websiteNames = [];
foreach ($this->getData('options') as $website) {
$websiteNames[$website->getWebsiteId()] = $website->getName();
}
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as & $item) {
$websites = [];
foreach ($item[$fieldName] as $websiteId) {
if (!isset($websiteNames[$websiteId])) {
continue;
}
$websites[] = $websiteNames[$websiteId];
}
$item[$fieldName] = implode(', ', $websites);
}
}
return $dataSource;
}
/**
* Prepare component configuration
* @return void
*/
public function prepare()
{
parent::prepare();
if ($this->storeManager->isSingleStoreMode()) {
$this->_data['config']['componentDisabled'] = true;
}
}
}
Đó là Magento xác thực được sử dụng để hiển thị trang web dựa trên điều kiện.