Question

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; ?>
Was it helpful?

Solution 2

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;
            ?>

OTHER TIPS

Try the below code:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$logo = $objectManager->get('\Magento\Theme\Block\Html\Header\Logo');
echo $logo->getLogoSrc();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top