![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/SerialNumber/Ui/Component/Listing/Column/ |
<?php /** * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * Krzysztof Majkowski <[email protected]> */ declare(strict_types=1); namespace Cnc\SerialNumber\Ui\Component\Listing\Column; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\Ui\Component\Listing\Columns\Column; class SourceCode extends Column { /** * @var SourceRepositoryInterface */ private $sourceRepository; /** * ProductId constructor. * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory * @param SourceRepositoryInterface $sourceRepository * @param array $components * @param array $data */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, SourceRepositoryInterface $sourceRepository, array $components = [], array $data = [] ) { parent::__construct($context, $uiComponentFactory, $components, $data); $this->sourceRepository = $sourceRepository; } /** * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource): array { foreach ($dataSource['data']['items'] as $index => $item) { try { $source = $this->sourceRepository->get($item['source_code']); $dataSource['data']['items'][$index]['origin_source_code'] = $item['source_code']; $dataSource['data']['items'][$index]['source_code'] = $source->getName(); } catch (NoSuchEntityException $e) { $dataSource['data']['items'][$index]['source_code'] = $item['source_code']; } } return $dataSource; } }