48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LingxingErp\Model\Source;
|
|
|
|
use Esun\LingxingErp\Model\Store\StoreRepository;
|
|
use Magento\Framework\Data\OptionSourceInterface;
|
|
|
|
class LingxingStore implements OptionSourceInterface
|
|
{
|
|
public function __construct(
|
|
private readonly StoreRepository $repository
|
|
) {
|
|
}
|
|
|
|
public function toOptionArray(): array
|
|
{
|
|
$options = [['value' => '', 'label' => __('-- Select a Lingxing store --')]];
|
|
$stores = $this->repository->getAll();
|
|
if ($stores === []) {
|
|
$options[] = [
|
|
'value' => '',
|
|
'label' => __('No local stores. Use Esun > Lingxing ERP > Stores > Sync Stores.'),
|
|
'disabled' => true,
|
|
];
|
|
return $options;
|
|
}
|
|
foreach ($stores as $store) {
|
|
$platformCode = (int)$store['platform_code'];
|
|
$storeId = (string)$store['store_id'];
|
|
$active = (int)$store['is_sync'] === 1 && (int)$store['status'] === 1;
|
|
$options[] = [
|
|
'value' => $platformCode . '|' . $storeId,
|
|
'disabled' => !$active,
|
|
'label' => sprintf(
|
|
'%s[%s / %d] %s (%s)',
|
|
$active ? '' : (string)__('Inactive: '),
|
|
(string)($store['platform_name'] ?? 'Platform'),
|
|
$platformCode,
|
|
(string)($store['store_name'] ?? $storeId),
|
|
$storeId
|
|
),
|
|
];
|
|
}
|
|
return $options;
|
|
}
|
|
}
|