82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Model;
|
|
|
|
use Magento\Store\Model\Store;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use Magento\Framework\App\Config\ScopeConfigInterface;
|
|
use Magento\Store\Model\ScopeInterface;
|
|
|
|
class StoreViewProvider
|
|
{
|
|
public function __construct(
|
|
private readonly StoreManagerInterface $storeManager,
|
|
private readonly ScopeConfigInterface $scopeConfig
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array{store_id:int,label:string,code:string,website:string,group:string,locale:string}>
|
|
*/
|
|
public function getStoreViewOptions(): array
|
|
{
|
|
$result = [];
|
|
$stores = $this->storeManager->getStores(true, false);
|
|
foreach ($stores as $store) {
|
|
if (!$store instanceof Store) {
|
|
continue;
|
|
}
|
|
|
|
if (!(int)$store->getId()) {
|
|
continue;
|
|
}
|
|
|
|
if (!$store->isActive()) {
|
|
continue;
|
|
}
|
|
|
|
$result[] = [
|
|
'store_id' => (int)$store->getId(),
|
|
'code' => (string)$store->getCode(),
|
|
'label' => (string)$store->getName(),
|
|
'website' => (string)$store->getWebsite()->getName(),
|
|
'group' => (string)$store->getGroup()->getName(),
|
|
'locale' => (string)$this->scopeConfig->getValue(
|
|
'general/locale/code',
|
|
ScopeInterface::SCOPE_STORE,
|
|
(int)$store->getId()
|
|
),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array{website:string,stores:array<int, array<string, mixed>>}>
|
|
*/
|
|
public function getStoreViewGroups(): array
|
|
{
|
|
$groups = [];
|
|
foreach ($this->getStoreViewOptions() as $store) {
|
|
$website = (string)$store['website'];
|
|
if (!isset($groups[$website])) {
|
|
$groups[$website] = [
|
|
'website' => $website,
|
|
'stores' => [],
|
|
];
|
|
}
|
|
$groups[$website]['stores'][] = $store;
|
|
}
|
|
|
|
return array_values($groups);
|
|
}
|
|
|
|
public function getDefaultSourceStoreId(): int
|
|
{
|
|
return Store::DEFAULT_STORE_ID;
|
|
}
|
|
}
|