File tree Expand file tree Collapse file tree 8 files changed +156
-0
lines changed Expand file tree Collapse file tree 8 files changed +156
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Noon \HideDefaultStoreCode \Helper ;
3+
4+ class Data extends \Magento \Framework \App \Helper \AbstractHelper
5+ {
6+ const XML_PATH_HIDE_DEFAULT_STORE_CODE = 'web/url/hide_default_store_code ' ;
7+
8+ /**
9+ *
10+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
11+ */
12+ protected $ scopeConfig ;
13+
14+ /**
15+ *
16+ * @param \Magento\Framework\App\Helper\Context $context
17+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
18+ */
19+ public function __construct (
20+ \Magento \Framework \App \Helper \Context $ context ,
21+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
22+ ) {
23+ parent ::__construct ($ context );
24+ $ this ->scopeConfig = $ scopeConfig ;
25+ }
26+
27+ /**
28+ *
29+ * @return boolean
30+ */
31+ public function isHideDefaultStoreCode ()
32+ {
33+ if ($ this ->scopeConfig ->getValue (self ::XML_PATH_HIDE_DEFAULT_STORE_CODE , \Magento \Store \Model \ScopeInterface::SCOPE_STORE )) {
34+ return true ;
35+ }
36+ return false ;
37+ }
38+ }
39+
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Noon \HideDefaultStoreCode \Plugin \Model ;
4+
5+ class HideDefaultStoreCode
6+ {
7+ /**
8+ *
9+ * @var \Noon\HideDefaultStoreCode\Helper\Data
10+ */
11+ protected $ helper ;
12+
13+ /**
14+ *
15+ * @var \Magento\Store\Model\StoreManagerInterface
16+ */
17+ protected $ storeManager ;
18+
19+ /**
20+ *
21+ * @param \Noon\HideDefaultStoreCode\Helper\Data $helper
22+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
23+ */
24+ public function __construct (
25+ \Noon \HideDefaultStoreCode \Helper \Data $ helper ,
26+ \Magento \Store \Model \StoreManagerInterface $ storeManager
27+ ){
28+ $ this ->helper = $ helper ;
29+ $ this ->storeManager = $ storeManager ;
30+ }
31+
32+ /**
33+ *
34+ * @param \Magento\Store\Model\Store $subject
35+ * @param string $url
36+ * @return string
37+ */
38+ public function afterGetBaseUrl (\Magento \Store \Model \Store $ subject , $ url )
39+ {
40+ if ($ this ->helper ->isHideDefaultStoreCode ()) {
41+ $ url = str_replace ('/ ' .$ this ->storeManager ->getDefaultStoreView ()->getCode ().'/ ' ,'/ ' , $ url );
42+ }
43+ return $ url ;
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ # HideDefaultStoreCode
2+
3+ Magento 2 plugin for hide * Default Store Code* from URL.
4+
5+ < https://bender.kr.ua/howto-hide-default-store-code-from-url-magento-2/ >
6+
7+ ![ howto-hide-default-store-code-from-url-magento-2] ( https://bender.kr.ua//content/images/2019/08/howto-hide-default-store-code-from-url-magento-2-1-1.png )
8+
9+ ***
10+
11+ ## Installation
12+
13+ 1 . Download ZIP file and extract to ** app/code/Noon/HideDefaultStoreCode** . If this path not exists, please create under Magento2 root directory.
14+ 2 . Run the command in Magento2 root directory:
15+
16+ ``` bash
17+ php bin/magento setup:upgrade
18+ ```
19+
20+ ## Configuration
21+
22+ * Stores > Configuration > General > Web > Url Options > Hide Default Store Code*
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:module:Magento_Config:etc/system_file.xsd" >
3+ <system >
4+ <section id =" web" >
5+ <group id =" url" >
6+ <field id =" hide_default_store_code" translate =" label" type =" select" sortOrder =" 100" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" canRestore =" 1" >
7+ <label >Hide Default Store Code</label >
8+ <source_model >Magento\Config\Model\Config\Source\Yesno</source_model >
9+ </field >
10+ </group >
11+ </section >
12+ </system >
13+ </config >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:module:Magento_Store:etc/config.xsd" >
3+ <default >
4+ <web >
5+ <url >
6+ <hide_default_store_code >0</hide_default_store_code >
7+ </url >
8+ </web >
9+ </default >
10+ </config >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:ObjectManager/etc/config.xsd" >
3+ <type name =" Magento\Store\Model\Store" >
4+ <plugin name =" Noon_hide_default_store_code" type =" \Noon\HideDefaultStoreCode\Plugin\Model\HideDefaultStoreCode" sortOrder =" 0" />
5+ </type >
6+ </config >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <!--
3+ /**
4+ * Copyright © 2015 Magento. All rights reserved.
5+ * See COPYING.txt for license details.
6+ */
7+ -->
8+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
9+ xsi:noNamespaceSchemaLocation=" urn:magento:framework:Module/etc/module.xsd" >
10+ <module name =" Noon_HideDefaultStoreCode" setup_version =" 1.0.0" />
11+ </config >
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © 2015 Magento. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ \Magento \Framework \Component \ComponentRegistrar::register (
7+ \Magento \Framework \Component \ComponentRegistrar::MODULE ,
8+ 'Noon_HideDefaultStoreCode ' ,
9+ __DIR__
10+ );
You can’t perform that action at this time.
0 commit comments