I have created multiple stores in one. Now when I change the store view it definitely changes and I have set the Base URLs for this store view accurately.
But when I try to get the current store view URL or Name I got the default store view name and URL.
I am trying to get using $storeManager->getStore()->getBaseUrl()
Any idea how I can get this ?
2 Answers
What you have to understand is the baseUrl is the same even you have multiple store views. the value that changes is for example : StoreId, StoreCode, storeName etc...
If you want to get the baseUrl, it will be the same in all stores :
$storeManager->getStore()->getBaseUrl() //domaine.com
if you want to get the currentUrl, it will be different in each store :
$storeManager->getStore()->getCurrentUrl() //domaine.com/?___store=default___from_store=pro
$storeManager->getStore()->getCurrentUrl($storeManager->getStore()->getId()) //domaine.com/?___store=default___from_store=2
If you want to set à specific store view, you append at the url ?___store=storeviewcode
:
domaine.com/?___store=pro
-
I guess magento gives the facility to each store view has its own Base URL. So there must be a way to get that, However if it is not possible then what is the alternate. I have tried your method but its still telling me that I am on default store view
from_store=default
– devZJan 17, 2020 at 10:50 -
Being precise I am in a Controller and receiving an Ajax and I want to know from which Store View it was generated.– devZJan 17, 2020 at 11:15
Magento Mage Core, Admin Static Blocks, or Phtml edits are usually includes getting url path such images, javascript, base url, media and store url. There are different ways to retrieve mentioned URL paths depending on where section you’re editing. To Retrieve URL path in STATIC BLOCK
To get SKIN URL
{{skin url='images/sampleimage.jpg'}}
To get Media URL
{{media url='/sampleimage.jpg'}}
To get Store URL
{{store url='mypage.html'}}
To get Base URL
{{base url='yourstore/mypage.html'}}
TO Retrieve URL path in PHTML Note: In editing PHTML don't forget to enclode the following code with PHP tag
Not secure Skin URL:
<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>
Secure Skin URL
<?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>
Get Current URL
$current_url = Mage::helper('core/url')->getCurrentUrl();
Get Home URL
$home_url = Mage::helper('core/url')->getHomeUrl();
Get Magento Media Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
Get Magento Media Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Get Magento Skin Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Get Magento Store Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Get Magento Js Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
-
Being precise I am in a Controller and receiving an Ajax and I want to know from which Store View it was generated.– devZJan 17, 2020 at 10:56
-