0

I have my custom theme in magento and in that theme in header the logo is uploaded. The logo is already uploaded there with correct path but still magento default logo is displaying after upgrading to 2.4.6.I know it is beacuse of something which is wrong in my custom theme app/design/../default.xml . Provoding logo code which is in my default.xml for logo

 <block class="Magento\Backend\Block\Page\Header" name="headertemplate="Magento_Theme::html/header.phtml">
        <block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
        <arguments>
                    <argument name="logoPathResolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver</argument>
                    <argument name="logo_size_resolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolver</argument>
        </arguments>
        </block>
        </block>

And code of my logo.phtml

 <?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Theme\Block\Html\Header\Logo $block
 */
$storeName = $block->getThemeName() ? $block->getThemeName() : $block->getLogoAlt();
/**
 * @var \Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolverInterface|null $logoSizeResolver
 */
$logoSizeResolver = $block->getLogoSizeResolver();
$logoWidth = $logoSizeResolver !== null && $logoSizeResolver->getWidth()
    ? $logoSizeResolver->getWidth()
    : $block->getLogoWidth();
$logoHeight = $logoSizeResolver !== null && $logoSizeResolver->getHeight()
    ? $logoSizeResolver->getHeight()
    : $block->getLogoHeight();
?>

<a
    class="new-logo"
    href="<?= $block->escapeUrl($block->getUrl('')) ?>"
    title="<?= $block->escapeHtmlAttr($storeName) ?>"
    aria-label="store logo">
    <img src="<?= $block->escapeUrl($block->getLogoSrc()) ?>"
         title="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
         alt="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
            <?= $block->getLogoWidth() ? 'width="' . $block->escapeHtmlAttr($block->getLogoWidth()) . '"' : '' ?>
            <?= $block->getLogoHeight() ? 'height="' . $block->escapeHtmlAttr($block->getLogoHeight()) . '"' : '' ?>
    />
</a>


enter code here

2 Answers 2

0

The code mentioned above is correct. You can find a reference in the following file path:

vendor/magento/module-theme/view/frontend/layout/default.xml

Logo Code in default.xml file

<block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
    <arguments>
        <argument name="logoPathResolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver</argument>
        <argument name="logo_size_resolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolver</argument>
    </arguments>
</block>

You can check your PHTML file code where the logo is displayed. Below is the default file that displays the logo.

Path :

vendor/magento/module-theme/view/frontend/templates/html/header/logo.phtml

Code :

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Theme\Block\Html\Header\Logo $block
 */
$storeName = $block->getThemeName() ? $block->getThemeName() : $block->getLogoAlt();
/**
 * @var \Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolverInterface|null $logoSizeResolver
 */
$logoSizeResolver = $block->getLogoSizeResolver();
$logoWidth = $logoSizeResolver !== null && $logoSizeResolver->getWidth()
    ? $logoSizeResolver->getWidth()
    : $block->getLogoWidth();
$logoHeight = $logoSizeResolver !== null && $logoSizeResolver->getHeight()
    ? $logoSizeResolver->getHeight()
    : $block->getLogoHeight();
?>
<span data-action="toggle-nav" class="action nav-toggle"><span><?= $block->escapeHtml(__('Toggle Nav')) ?></span></span>
<a
    class="logo"
    href="<?= $block->escapeUrl($block->getUrl('')) ?>"
    title="<?= $block->escapeHtmlAttr($storeName) ?>"
    aria-label="store logo">
    <img src="<?= $block->escapeUrl($block->getLogoSrc()) ?>"
         title="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
         alt="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
            <?= $logoWidth ? 'width="' . $block->escapeHtmlAttr($logoWidth) . '"' : '' ?>
            <?= $logoHeight ? 'height="' . $block->escapeHtmlAttr($logoHeight) . '"' : '' ?>
    />
</a>

If the changes are not working, please enable the default theme and check if the logo is visible. Also, ensure that your logo is uploaded in the theme configuration from the admin panel.

5
  • I have checked it by changing logo.phtml code in my custom theme. but still logo is not displaying. I think the issue is with arguments and LogoSizeResolver Commented Oct 31, 2023 at 13:17
  • Is the logo visible on the default Magento Luma theme? Can you check it and update me?
    – Msquare
    Commented Oct 31, 2023 at 13:53
  • Yes,It is visible there Commented Nov 1, 2023 at 6:13
  • It means that there might be an issue with your custom theme related to the logo. Please compare it with the default theme and try to identify the issue. You can temporarily remove the Magento_Theme folder from your custom theme and check if the problem persists. Then, gradually add the theme's files back one by one to pinpoint the source of the issue.
    – Msquare
    Commented Nov 2, 2023 at 7:45
  • I found out and i think the issue is with this arguments argument name="logoPathResolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver</argument> <argument name="logo_size_resolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoSizeResolver</argument> but i am not sure whether i have to redeclare viewmodel in my custom theme becuase previously in magento 2.4.0 there was no viewModel in Magento_theme Commented Nov 2, 2023 at 8:26
0
  1. The Magento\Backend\Block\Page\Header class is used for the backend template (admin theme). It should not be used for the frontend theme.
  2. If you need to override the logo.phtml file, you don't need to redeclare the layout instructors for the logo block in the default.xml file. Instead, you can directly copy that file from the Magento_Theme module (located at vendor/magento/module-theme/view/frontend/templates/html/header/logo.phtml) to <your_theme_dir>/Magento_Theme/templates/header/ directory in your theme and make the necessary modifications there.

For example, if your theme is called Magetu/winter and it is located in the app/design directory, the logo.phtml file in your theme will have the following file path: app/design/Magetu/winter/Magento_Theme/templates/header/logo.phtml.

You can read more about Override a layout at https://developer.adobe.com/commerce/frontend-core/guide/layouts/override/

  1. Remember to clean the Page Cache cache type (full_page) after uploading the logo to ensure that the changes take effect.

Regarding the issue of changing the header logo in the admin doesn't reflect on the frontend, there is a related issue in recent Magento versions, including version 2.4.6. https://github.com/magento/magento2/issues/35952

This issue has been resolved and merged into the 2.4-develop branch of the Magento repository through pull request #36008 at https://github.com/magento/magento2/pull/36008/.

I created a custom composer patch file (diff file) for Magento and Adobe Commerce version 2.4.5 and higher, using that pull request:

diff --git a/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php b/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
index a640526517d47..d133388e4a4c1 100644
--- a/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
+++ b/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
@@ -54,9 +54,13 @@ public function getPath(): ?string
         if ($order instanceof Order) {
             $storeId = $order->getStoreId();
         }
+        $scopeType = ScopeInterface::SCOPE_STORE;
+        if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
+            $scopeType = ScopeInterface::SCOPE_WEBSITE;
+        }
         $salesLogoPath = $this->scopeConfig->getValue(
             'sales/identity/logo_html',
-            ScopeInterface::SCOPE_STORE,
+            $scopeType,
             $storeId
         );

@@ -66,7 +70,7 @@ public function getPath(): ?string

         $headerLogoPath = $this->scopeConfig->getValue(
             'design/header/logo_src',
-            ScopeInterface::SCOPE_STORE,
+            $scopeType,
             $storeId
         );

diff --git a/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php b/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
index 1a10fe9177320..5be2cf9360ed4 100644
--- a/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
+++ b/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
@@ -39,9 +39,13 @@ public function __construct(
     public function getPath(): ?string
     {
         $path = null;
+        $scopeType = ScopeInterface::SCOPE_STORE;
+        if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
+            $scopeType = ScopeInterface::SCOPE_WEBSITE;
+        }
         $storeLogoPath = $this->scopeConfig->getValue(
             'design/header/logo_src',
-            ScopeInterface::SCOPE_STORE
+            $scopeType
         );
         if ($storeLogoPath !== null) {
             $path = Logo::UPLOAD_DIR . '/' . $storeLogoPath;

To apply this custom composer patch, I suggest using the Vaimo Composer Patches plugin https://github.com/vaimo/composer-patches. This plugin can apply the patch to multiple files within a diff file.

Alternatively, if you prefer to use the Cweagans Composer Patches plugin https://github.com/cweagans/composer-patches, you can refer to the official Adobe Commerce documentation at https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/patches/apply.html?lang=en#composer

As the Cweagans Composer Patches plugin does not support applying the patch to multiple files within a diff file, you'll need to create 2 separate diff files:

  • The patch file for the magento/module-theme module's composer package:
diff --git a/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php b/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
index 1a10fe9177320..5be2cf9360ed4 100644
--- a/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
+++ b/vendor/magento/module-theme/ViewModel/Block/Html/Header/LogoPathResolver.php
@@ -39,9 +39,13 @@ public function __construct(
     public function getPath(): ?string
     {
         $path = null;
+        $scopeType = ScopeInterface::SCOPE_STORE;
+        if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
+            $scopeType = ScopeInterface::SCOPE_WEBSITE;
+        }
         $storeLogoPath = $this->scopeConfig->getValue(
             'design/header/logo_src',
-            ScopeInterface::SCOPE_STORE
+            $scopeType
         );
         if ($storeLogoPath !== null) {
             $path = Logo::UPLOAD_DIR . '/' . $storeLogoPath;

  • The patch file for the magento/module-sales module's composer package:
diff --git a/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php b/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
index a640526517d47..d133388e4a4c1 100644
--- a/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
+++ b/vendor/magento/module-sales/ViewModel/Header/LogoPathResolver.php
@@ -54,9 +54,13 @@ public function getPath(): ?string
         if ($order instanceof Order) {
             $storeId = $order->getStoreId();
         }
+        $scopeType = ScopeInterface::SCOPE_STORE;
+        if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
+            $scopeType = ScopeInterface::SCOPE_WEBSITE;
+        }
         $salesLogoPath = $this->scopeConfig->getValue(
             'sales/identity/logo_html',
-            ScopeInterface::SCOPE_STORE,
+            $scopeType,
             $storeId
         );

@@ -66,7 +70,7 @@ public function getPath(): ?string

         $headerLogoPath = $this->scopeConfig->getValue(
             'design/header/logo_src',
-            ScopeInterface::SCOPE_STORE,
+            $scopeType,
             $storeId
         );

4
  • Yes, I did the same. Previously when my magento version was 2.4.0 . It was working but now it is not working in 2.4.6 Commented Nov 1, 2023 at 6:15
  • @TishaJhanwar I added a solution in my answer for the issue where changing the header logo in the admin does not reflect on the frontend.
    – Tu Van
    Commented Nov 1, 2023 at 12:01
  • I checked it but it is not working for me! Commented Nov 6, 2023 at 11:46
  • @TishaJhanwar try removing your customization in the default.xml file and clear the cache to see if the issue still persists. If the issue remains, it is possible that this issue is not caused by your customization. You can utilize the Template path hints feature or the Developer Toolbar by Vincent Pietri (Vpietri) and Xdebug to debug this issue. Template path hints: experienceleague.adobe.com/docs/commerce-admin/systems/tools/…. Developer Toolbar by Vincent Pietri (Vpietri): github.com/vpietri/magento2-developer-quickdevbar
    – Tu Van
    Commented Nov 8, 2023 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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