1

I just started developing a module in Magento 2. It is a copy of a module I made in Magento 1.

I'm already stuck with Magento 2 logic.

I want to get the logo URL of every store view.

In Magento 1 I went like this :

Mage::getDesign()->getSkinUrl(Mage::getStoreConfig('design/header/logo_src', $storeId));

with $storeId being a specific store view ID.

I can't find a way to do it in Magento 2. Actually I have this.

$om = \Magento\Framework\App\ObjectManager::getInstance(); 
$logo=$om->get('Magento\Theme\Block\Html\Header\Logo');
$logoUrl=$logo->getLogoSrc();

But it only gives me one Url and I don't see how to inject the store Id in the process to have the other.

I guess that I have to change some Global Value which define the store but I can't find How.

I have found similar questions but answers don't apply to my case because I'm in a Controller so it's only back end.

If someone got an idea. I would be really thankful.

0

First of all using ObjectManager is not a recommended way. You should read a bit more into using Service Contract. Right now the core Theme module doesn't have service contract for what we want to do here, so you should inject the LogoFactory in.

Now to answer your question:

Inject \Magento\Framework\App\Config\ScopeConfigInterface into your controller, then use it to get the logo path, sample fore core code Magento\Theme\Block\Html\Header\Logo:_getLogoUrl :

$folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR;
        $storeLogoPath = $this->_scopeConfig->getValue(
            'design/header/logo_src',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        $path = $folderName . '/' . $storeLogoPath;
        $logoUrl = $this->_urlBuilder
                ->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path;
  • Thank you. Sadly this doesn't adress my specific problem. It is only giving me the same thing : ONE logo Url ( the default one). I already had this one. My problem is about having the other logoUrl by using the storeId somewhere. the getValue method take a third argument( $scopeCode ).I use it to retrieve localeCode for each specific store. $this->_scopeConfig>getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE,$storeId); It work well but when I use it on design/header/logo_src I am getting a null for every $storeId different than the default one – Thierry Feb 19 '18 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.