Add store codes to urls is set to yes.
Store code is: test.
Default homepage for that store loads correctly: home cms page for that particular store.
In the menu the store code is added to the urls: www.example.com/test/men.html
But when I add this code in a template file (one called in the homepage for example):
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $store = $objectManager->create('\Magento\Store\Model\StoreManagerInterface'); echo "Code: ".$store->getStore()->getCode(); echo "Name: ".$store->getStore()->getName();
I get the default store code and default store code name.
Why is that? I didn't edit the index file or htaccess.
If I would go ahead and add this to the index file:
$params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'test'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);
Then it will show the right store code, but I don't want to edit the index file as the client must be able create the stores in the admin without us editing files.