init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Model\Source;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class LingxingWarehouse implements OptionSourceInterface
|
||||
{
|
||||
public function __construct(private readonly ResourceConnection $resource)
|
||||
{
|
||||
}
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$options = [['value' => '', 'label' => __('Not mapped')]];
|
||||
$connection = $this->resource->getConnection();
|
||||
$table = $this->resource->getTableName('esun_lingxing_warehouse');
|
||||
if (!$connection->isTableExists($table)) {
|
||||
return $options;
|
||||
}
|
||||
$rows = $connection->fetchAll($connection->select()
|
||||
->from($table, ['wid', 'warehouse_name', 'source_code'])
|
||||
->where('warehouse_type = ?', 3)
|
||||
->where('is_deleted = ?', 0)
|
||||
->where('lingxing_status = ?', 1)
|
||||
->order(['warehouse_type ASC', 'warehouse_name ASC']));
|
||||
foreach ($rows as $row) {
|
||||
$options[] = [
|
||||
'value' => (string)$row['wid'],
|
||||
'label' => sprintf(
|
||||
'%s (WID %s%s)',
|
||||
$row['warehouse_name'],
|
||||
$row['wid'],
|
||||
$row['source_code'] ? ' / mapped to ' . $row['source_code'] : ''
|
||||
),
|
||||
];
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user