74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Esun\Store\Block;
|
|
|
|
use Magento\Directory\Helper\Data;
|
|
use Magento\Framework\Url\Helper\Data as UrlHelper;
|
|
|
|
class Switcher extends \Magento\Store\Block\Switcher
|
|
{
|
|
public function __construct(
|
|
\Magento\Framework\View\Element\Template\Context $context,
|
|
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
|
|
protected \Magento\Store\Model\GroupFactory $storeGroupFactory,
|
|
array $data = [],
|
|
?UrlHelper $urlHelper = null
|
|
) {
|
|
parent::__construct($context, $postDataHelper, $data, $urlHelper);
|
|
}
|
|
|
|
/**
|
|
* Get raw groups.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getRawGroups()
|
|
{
|
|
if (!$this->hasData('raw_groups')) {
|
|
$websiteGroups = $this->_storeManager->getWebsite()->getGroups();
|
|
|
|
$groups = [];
|
|
foreach ($websiteGroups as $group) {
|
|
$groups[$group->getId()] = $group;
|
|
}
|
|
$this->setData('raw_groups', $groups);
|
|
}
|
|
return $this->getData('raw_groups');
|
|
}
|
|
|
|
/**
|
|
* Get raw stores.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getRawStores()
|
|
{
|
|
if (!$this->hasData('raw_stores')) {
|
|
$websiteStores = $this->_storeManager->getWebsite()->getStores();
|
|
$stores = [];
|
|
foreach ($websiteStores as $store) {
|
|
/* @var $store \Magento\Store\Model\Store */
|
|
if (!$store->isActive()) {
|
|
continue;
|
|
}
|
|
$localeCode = $this->_scopeConfig->getValue(
|
|
Data::XML_PATH_DEFAULT_LOCALE,
|
|
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
|
$store
|
|
);
|
|
$store->setLocaleCode($localeCode);
|
|
$params = ['_query' => []];
|
|
if (!$this->isStoreInUrl()) {
|
|
$params['_query']['___store'] = $store->getCode();
|
|
}
|
|
$baseUrl = $store->getUrl('', $params);
|
|
|
|
$store->setHomeUrl($baseUrl);
|
|
$stores[$store->getGroupId()][$store->getId()] = $store;
|
|
}
|
|
$this->setData('raw_stores', $stores);
|
|
}
|
|
return $this->getData('raw_stores');
|
|
}
|
|
}
|