45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\OrderNumber\Model;
|
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface;
|
|
use Magento\Store\Model\ScopeInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
|
|
class Config
|
|
{
|
|
public const XML_PATH_SITE_NAME = 'sales/order_number/site_name';
|
|
public const XML_PATH_START_NUMBER = 'sales/order_number/start_number';
|
|
|
|
public function __construct(
|
|
private readonly ScopeConfigInterface $scopeConfig,
|
|
private readonly StoreManagerInterface $storeManager
|
|
) {
|
|
}
|
|
|
|
public function getSiteName(int $websiteId): string
|
|
{
|
|
$configuredName = trim((string)$this->scopeConfig->getValue(
|
|
self::XML_PATH_SITE_NAME,
|
|
ScopeInterface::SCOPE_WEBSITE,
|
|
$websiteId
|
|
));
|
|
|
|
if ($configuredName !== '') {
|
|
return $configuredName;
|
|
}
|
|
|
|
return (string)$this->storeManager->getWebsite($websiteId)->getCode();
|
|
}
|
|
|
|
public function getStartNumber(int $websiteId): int
|
|
{
|
|
return max(1, (int)$this->scopeConfig->getValue(
|
|
self::XML_PATH_START_NUMBER,
|
|
ScopeInterface::SCOPE_WEBSITE,
|
|
$websiteId
|
|
));
|
|
}
|
|
}
|