21 use Zend\Uri\UriFactory;
233 private $_isReadOnly =
false;
316 private $_storeManager;
321 private $urlModifier;
326 private $eventManager;
360 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
363 \
Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
371 \
Magento\Framework\Session\SidResolverInterface $sidResolver,
380 $isCustomEntryPoint =
false,
382 \
Magento\Framework\Event\ManagerInterface $eventManager =
null 384 $this->_coreFileStorageDatabase = $coreFileStorageDatabase;
387 $this->_configCacheType = $configCacheType;
389 $this->_configDataResource = $configDataResource;
393 $this->_sidResolver = $sidResolver;
394 $this->_httpContext = $httpContext;
398 $this->_currencyInstalled = $currencyInstalled;
402 ->get(\
Magento\Framework\Event\ManagerInterface::class);
433 ->get(\
Magento\MediaStorage\Helper\File\Storage\Database::class);
456 if (!$this->_session->isSessionExists()) {
457 $this->_session->setName(
'store_' . $this->
getCode());
458 $this->_session->start();
470 $validator = new \Magento\Framework\Validator\DataObject();
472 $storeLabelRule = new \Zend_Validate_NotEmpty();
474 $validator->addRule($storeLabelRule,
'name');
476 $storeCodeRule = new \Zend_Validate_Regex(
'/^[a-z]+[a-z0-9_]*$/i');
477 $storeCodeRule->setMessage(
479 'The store code may contain only letters (a-z), numbers (0-9) or underscore (_),' 480 .
' and the first character must be a letter.' 484 $validator->addRule($storeCodeRule,
'code');
496 public function load($key, $field =
null)
498 if (!is_numeric($key) && $field ===
null) {
502 return parent::load($key, $field);
548 if (
$data ===
null) {
575 return $this->websiteRepository->getById($this->
getWebsiteId());
585 public function getUrl($route =
'',
$params = [])
588 $url = $this->_url->setScope($this);
589 if ($this->_storeManager->getStore()->getId() != $this->
getId()) {
590 $params[
'_scope_to_url'] =
true;
609 $cacheKey =
$type .
'/' . ($secure ===
null ?
'null' : ($secure ?
'true' :
'false'));
610 if (!isset($this->_baseUrlCache[$cacheKey])) {
655 throw new \InvalidArgumentException(
'Invalid base url type');
658 if (
false !== strpos(
$url, self::BASE_URL_PLACEHOLDER)) {
659 $url = str_replace(self::BASE_URL_PLACEHOLDER, $this->_request->getDistroBaseUrl(),
$url);
662 $this->_baseUrlCache[$cacheKey] = $this->getUrlModifier()->execute(
663 rtrim(
$url,
'/') .
'/',
664 \
Magento\Framework\Url\ModifierInterface::MODE_BASE
668 return $this->_baseUrlCache[$cacheKey];
699 if ($this->getForceDisableRewrites() || !$this->
getConfig(self::XML_PATH_USE_REWRITES)) {
701 $indexFileName =
'index.php';
703 $indexFileName = basename($_SERVER[
'SCRIPT_FILENAME']);
705 $url .= $indexFileName .
'/';
732 if (!$this->
getConfig(self::XML_PATH_USE_REWRITES) && $this->_coreFileStorageDatabase->checkDbUsage()) {
760 return !($this->hasDisableStoreInUrl() && $this->getDisableStoreInUrl())
761 && $this->
getConfig(self::XML_PATH_STORE_IN_URL);
771 return $this->
_getData(self::STORE_ID);
781 if ($this->_isFrontSecure ===
null) {
782 $this->_isFrontSecure = $this->_config
803 if ($this->_request->isSecure()) {
810 if (!$secureBaseUrl || !$secureFrontend) {
814 $uri = UriFactory::factory($secureBaseUrl);
815 $port = $uri->getPort();
816 $serverPort = $this->_request->getServer(
'SERVER_PORT');
817 $isSecure = $uri->getScheme() ==
'https' && isset($serverPort) && $port == $serverPort;
832 $configValue = $this->
getConfig(self::XML_PATH_PRICE_SCOPE);
833 if ($configValue == self::PRICE_SCOPE_GLOBAL) {
846 $currency = $this->
getData(
'base_currency');
847 if (
null === $currency) {
849 $this->
setData(
'base_currency', $currency);
872 $currency = $this->
getData(
'default_currency');
873 if (
null === $currency) {
875 $this->
setData(
'default_currency', $currency);
892 $defaultCode = $this->_storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode();
921 return array_shift($codes);
935 $codes = $this->
getData(
'available_currency_codes');
936 if (
null === $codes) {
940 if (!in_array($baseCurrencyCode, $codes)) {
941 $codes[] = $baseCurrencyCode;
944 $disallowedBaseCodeIndex = array_keys($codes);
945 $disallowedBaseCodeIndex = array_pop($disallowedBaseCodeIndex);
946 $this->
setData(
'disallowed_base_currency_code_index', $disallowedBaseCodeIndex);
948 $this->
setData(
'available_currency_codes', $codes);
952 if ($skipBaseNotAllowed) {
953 $disallowedBaseCodeIndex = $this->
getData(
'disallowed_base_currency_code_index');
954 if (
null !== $disallowedBaseCodeIndex) {
955 unset($codes[$disallowedBaseCodeIndex]);
968 return explode(
',', $this->
getConfig($this->_currencyInstalled));
978 $currency = $this->
getData(
'current_currency');
980 if ($currency ===
null) {
984 if (!$baseCurrency->getRate($currency)) {
985 $currency = $baseCurrency;
988 $this->
setData(
'current_currency', $currency);
1013 return $this->
getGroup()->getRootCategoryId();
1024 $this->setGroupId(
$group->getId());
1038 return $this->groupRepository->get($this->
getGroupId());
1048 return $this->
_getData(
'website_id');
1060 $this->_storeManager->reinitStores();
1062 $event = $this->_eventPrefix .
'_add';
1064 $event = $this->_eventPrefix .
'_edit';
1068 $this->eventManager->dispatch($event, [
'store' =>
$store]);
1070 return parent::afterSave();
1088 return $this->
_getData(
'group_id');
1114 return $this->
_getData(
'is_active');
1122 return $this->
setData(
'is_active', $isActive);
1132 return $this->
_getData(
'default_group_id');
1142 if (!$this->
getId()) {
1146 return $this->
getGroup()->getStoresCount() > 1;
1160 return $this->
getGroup()->getDefaultStoreId() == $this->
getId();
1173 $sidQueryParam = $this->_sidResolver->getSessionIdQueryParam($this->
_getSession());
1174 $requestString = $this->_url->escape(ltrim($this->_request->getRequestString(),
'/'));
1176 $storeUrl = $this->getUrl(
'', [
'_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]);
1178 if (!filter_var($storeUrl, FILTER_VALIDATE_URL)) {
1182 $storeParsedUrl = parse_url($storeUrl);
1184 $storeParsedQuery = [];
1185 if (isset($storeParsedUrl[
'query'])) {
1186 parse_str($storeParsedUrl[
'query'], $storeParsedQuery);
1189 $currQuery = $this->_request->getQueryValue();
1190 if (isset($currQuery[$sidQueryParam])
1191 && !empty($currQuery[$sidQueryParam])
1192 && $this->
_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam]
1194 unset($currQuery[$sidQueryParam]);
1197 foreach ($currQuery as $key =>
$value) {
1198 $storeParsedQuery[$key] =
$value;
1202 $storeParsedQuery[
'___store'] = $this->
getCode();
1205 if ($fromStore !==
false) {
1206 $storeParsedQuery[
'___from_store'] = $fromStore ===
1207 true ? $this->_storeManager->getStore()->getCode() : $fromStore;
1210 $requestStringParts = explode(
'?', $requestString, 2);
1211 $requestStringPath = $requestStringParts[0];
1212 if (isset($requestStringParts[1])) {
1213 parse_str($requestStringParts[1], $requestString);
1215 $requestString = [];
1218 $currentUrlQueryParams = array_merge($requestString, $storeParsedQuery);
1220 $currentUrl = $storeParsedUrl[
'scheme']
1222 . $storeParsedUrl[
'host']
1223 . (isset($storeParsedUrl[
'port']) ?
':' . $storeParsedUrl[
'port'] :
'')
1224 . $storeParsedUrl[
'path']
1225 . $requestStringPath
1226 . ($currentUrlQueryParams ?
'?' . http_build_query($currentUrlQueryParams) :
'');
1238 return (
bool)$this->
_getData(
'is_active');
1249 return parent::beforeDelete();
1261 $this->_storeManager->reinitStores();
1262 $this->eventManager->dispatch($this->_eventPrefix .
'_delete', [
'store' =>
$store]);
1264 parent::afterDelete();
1265 $this->_configCacheType->clean();
1267 if ($this->
getId() === $this->
getGroup()->getDefaultStoreId()) {
1268 $ids = $this->
getGroup()->getStoreIds();
1269 if (!empty($ids) && count($ids) > 1) {
1270 unset($ids[$this->
getId()]);
1271 $defaultId = current($ids);
1275 $this->
getGroup()->setDefaultStoreId($defaultId);
1289 $this->_config->reinit();
1290 $this->_dirCache = [];
1291 $this->_baseUrlCache = [];
1292 $this->_urlCache = [];
1306 $this->_isReadOnly = (bool)
$value;
1308 return $this->_isReadOnly;
1318 if (
null === $this->_frontendName) {
1319 $storeGroupName = (string)$this->_config
1321 $this->_frontendName = !empty($storeGroupName) ? $storeGroupName : $this->
getGroup()->getName();
1333 return $this->information->getFormattedAddress($this);
1352 return isset($parsedUrl[
'path']) ? $parsedUrl[
'path'] :
'/';
1370 return 'Store View';
1397 private function getUrlModifier()
1399 if ($this->urlModifier ===
null) {
1401 \
Magento\Framework\Url\ModifierInterface::class
1405 return $this->urlModifier;
const PRICE_SCOPE_WEBSITE
const XML_PATH_UNSECURE_BASE_STATIC_URL
const XML_PATH_UNSECURE_BASE_URL
const XML_PATH_CURRENCY_DEFAULT
_getExtensionAttributes()
const XML_PATH_STORE_IN_URL
const XML_PATH_SECURE_BASE_MEDIA_URL
_updatePathUseRewrites($url)
const CUSTOM_ENTRY_POINT_PARAM
const XML_PATH_UNSECURE_BASE_MEDIA_URL
const XML_PATH_ENABLE_HSTS
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
_updatePathUseStoreView($url)
setStoreGroupId($storeGroupId)
const BASE_URL_PLACEHOLDER
getCurrentUrl($fromStore=true)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\ResourceModel\Store $resource, \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase, \Magento\Framework\App\Cache\Type\Config $configCacheType, \Magento\Framework\UrlInterface $url, \Magento\Framework\App\RequestInterface $request, \Magento\Config\Model\ResourceModel\Config\Data $configDataResource, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Config\ReinitableConfigInterface $config, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\App\Http\Context $httpContext, \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Store\Model\Information $information, $currencyInstalled, \Magento\Store\Api\GroupRepositoryInterface $groupRepository, \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, $isCustomEntryPoint=false, array $data=[], \Magento\Framework\Event\ManagerInterface $eventManager=null)
const XML_PATH_USE_REWRITES
setCurrentCurrencyCode($code)
setExtensionAttributes(\Magento\Store\Api\Data\StoreExtensionInterface $extensionAttributes)
const XML_PATH_CURRENCY_BASE
const XML_PATH_SECURE_BASE_LINK_URL
_getMediaScriptUrl(Filesystem $filesystem, $secure)
const XML_PATH_UNSECURE_BASE_LINK_URL
const XML_PATH_ENABLE_UPGRADE_INSECURE
$_coreFileStorageDatabase
const XML_PATH_SECURE_IN_FRONTEND
const XML_PATH_PRICE_SCOPE
getData($key='', $index=null)
setData($key, $value=null)
const XML_PATH_SECURE_BASE_URL
setWebsite(Website $website)
const XML_PATH_CURRENCY_ALLOW
getAvailableCurrencyCodes($skipBaseNotAllowed=false)
getBaseUrl($type=UrlInterface::URL_TYPE_LINK, $secure=null)
const URL_TYPE_DIRECT_LINK
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
const XML_PATH_SECURE_BASE_STATIC_URL
const XML_PATH_SECURE_IN_ADMINHTML
_getValidationRulesBeforeSave()
const MEDIA_REWRITE_SCRIPT
if(!isset($_GET['name'])) $name