40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LingxingErp\Plugin\InventoryAdminUi;
|
|
|
|
use Esun\LingxingErp\Model\Warehouse\WarehouseRepository;
|
|
use Magento\InventoryAdminUi\Ui\DataProvider\SourceDataProvider;
|
|
|
|
class SourceDataProviderPlugin
|
|
{
|
|
public function __construct(private readonly WarehouseRepository $warehouseRepository)
|
|
{
|
|
}
|
|
|
|
/** @param array<string, mixed> $result */
|
|
public function afterGetData(SourceDataProvider $subject, array $result): array
|
|
{
|
|
if ($subject->getName() !== SourceDataProvider::SOURCE_FORM_NAME) {
|
|
return $result;
|
|
}
|
|
|
|
foreach ($result as $sourceCode => &$sourceData) {
|
|
if ($sourceCode === '' || !is_array($sourceData)) {
|
|
continue;
|
|
}
|
|
if (!isset($sourceData['general']) || !is_array($sourceData['general'])) {
|
|
continue;
|
|
}
|
|
if (array_key_exists('lingxing_wid', $sourceData['general'])) {
|
|
continue;
|
|
}
|
|
$wid = $this->warehouseRepository->getWidForSource((string)$sourceCode);
|
|
$sourceData['general']['lingxing_wid'] = $wid === null ? '' : (string)$wid;
|
|
}
|
|
unset($sourceData);
|
|
|
|
return $result;
|
|
}
|
|
}
|