1

I was trying to pull the logo_src from the database table core_config_data but can't return it on the frontend. I was trying to do this via objectManager and know that this is not the correct way. However I want to test if the idea that I have works. The odd thing is I can get all other values except this one.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('design/header/logo_src');

What I eventually want to achieve is to combine this with the storeswitcher and do something like this. In this way I can get the uploaded logo's from each store and display it in an overview.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('design/header/logo_src', $block->getCurrentStoreId()

I know the Magento 1 equivalent (see the code below), but find it hard to translate this to Magento 2. Does anybody have a solution for me?

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

Current code

    <?php foreach ($block->getGroups() as $_group): ?>
    <?php if (!($_group->getId() == $block->getCurrentGroupId())): ?>
        <a href="#" data-post='<?= /* @noEscape */ $block->getTargetStorePostData($_group->getDefaultStore()) ?>'>
            <?= $block->escapeHtml($_group->getName()) ?>
        <?
            $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
            $logo = $objectManager->get('\Magento\Theme\Block\Html\Header\Logo');
            echo $logo->getLogoSrc();           
        ?>                  
        </a>        
    <?php endif; ?>
    <?php endforeach; ?>
0

Try the below code:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$logo = $objectManager->get('\Magento\Theme\Block\Html\Header\Logo');
echo $logo->getLogoSrc();
  • Hi, This gives me the same effect as the following code which I added already. <?= $block->getLayout()->getBlock('logo')->getLogoSrc() ?> – Remco Hendriks Jul 23 '18 at 14:56
  • It shows the same logo URL over and over and over – Remco Hendriks Jul 23 '18 at 14:57
  • What do you want then? You want logo store wise? – Sukumar Gorai Jul 23 '18 at 14:59
  • Exactly, that is what i want to achieve :) – Remco Hendriks Jul 23 '18 at 15:02
  • On which file you are trying to call this code? – Sukumar Gorai Jul 23 '18 at 15:06
0

Managed to solve it took a while but finally got it working the only thing left is to convert it to a Magento module without objectManager. If anyone has some adjustments to make it better please have a go.. :)

            <?php
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $storeID = $_group->getDefaultStoreId();
                $folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR;
                $storeLogoPath = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('design/header/logo_src', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeID);
                $path = '<img src="/pub/media/' . $folderName . '/' . $storeLogoPath . '"/>';
            ?>
            <?=
                $path;
            ?>

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.