Skip to content

Commit ee8b359

Browse files
committed
Merge branch 'fix-wrong-logo-path-on-print-order-page' of github.com:ihor-sviziev/magento2 into 2.4-develop
2 parents 2397069 + c6a5b77 commit ee8b359

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

app/code/Magento/Sales/ViewModel/Header/LogoPathResolver.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
namespace Magento\Sales\ViewModel\Header;
99

10+
use Magento\Config\Model\Config\Backend\Image\Logo;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Store\Model\ScopeInterface;
12-
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface;
12+
use Magento\Framework\Registry;
1313
use Magento\Framework\View\Element\Block\ArgumentInterface;
1414
use Magento\Sales\Model\Order;
15-
use Magento\Framework\Registry;
15+
use Magento\Store\Model\ScopeInterface;
16+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface;
1617

1718
/**
1819
* Class for resolving logo path
@@ -25,8 +26,6 @@ class LogoPathResolver implements LogoPathResolverInterface, ArgumentInterface
2526
private $scopeConfig;
2627

2728
/**
28-
* Core registry
29-
*
3029
* @var Registry
3130
*/
3231
private $coreRegistry;
@@ -50,20 +49,31 @@ public function __construct(
5049
*/
5150
public function getPath(): ?string
5251
{
53-
$path = null;
5452
$storeId = null;
5553
$order = $this->coreRegistry->registry('current_order');
5654
if ($order instanceof Order) {
5755
$storeId = $order->getStoreId();
5856
}
59-
$storeLogoPath = $this->scopeConfig->getValue(
57+
$salesLogoPath = $this->scopeConfig->getValue(
6058
'sales/identity/logo_html',
6159
ScopeInterface::SCOPE_STORE,
6260
$storeId
6361
);
64-
if ($storeLogoPath !== null) {
65-
$path = 'sales/store/logo_html/' . $storeLogoPath;
62+
63+
if ($salesLogoPath !== null) {
64+
return 'sales/store/logo_html/' . $salesLogoPath;
6665
}
67-
return $path;
66+
67+
$headerLogoPath = $this->scopeConfig->getValue(
68+
'design/header/logo_src',
69+
ScopeInterface::SCOPE_STORE,
70+
$storeId
71+
);
72+
73+
if ($headerLogoPath !== null) {
74+
return Logo::UPLOAD_DIR . '/' . $headerLogoPath;
75+
}
76+
77+
return null;
6878
}
6979
}

dev/tests/integration/testsuite/Magento/Sales/Block/Order/PrintOrder/LogoTest.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
*/
66
namespace Magento\Sales\Block\Order\PrintOrder;
77

8-
use Magento\Framework\View\LayoutInterface;
9-
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Framework\App\Filesystem\DirectoryList;
109
use Magento\Framework\App\State;
11-
use Magento\Theme\Block\Html\Header\Logo;
1210
use Magento\Framework\Filesystem;
1311
use Magento\Framework\Filesystem\Directory\WriteInterface;
14-
use Magento\Framework\App\Filesystem\DirectoryList;
1512
use Magento\Framework\ObjectManagerInterface;
16-
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver as LogoPathResolverDefault;
13+
use Magento\Framework\View\LayoutInterface;
1714
use Magento\Sales\ViewModel\Header\LogoPathResolver as LogoPathResolverSales;
18-
use \PHPUnit\Framework\TestCase;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\Theme\Block\Html\Header\Logo;
17+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver as LogoPathResolverDefault;
18+
use PHPUnit\Framework\TestCase;
1919

2020
class LogoTest extends TestCase
2121
{
@@ -71,4 +71,33 @@ public function testGetLogoSrc(): void
7171
$this->mediaDirectory->delete($defaultPath);
7272
$this->mediaDirectory->delete($salesPath);
7373
}
74+
75+
/**
76+
* Checks that fallback to header logo works fine
77+
*
78+
* @magentoConfigFixture default_store design/header/logo_src default/logo.jpg
79+
* @throws \Magento\Framework\Exception\FileSystemException
80+
*/
81+
public function testGetLogoSrcWithFallback(): void
82+
{
83+
$host = 'http://localhost/media/';
84+
$defaultLogoFile = 'logo.jpg';
85+
$defaultPath = 'logo/default/' . $defaultLogoFile;
86+
$this->mediaDirectory->writeFile($defaultPath, '');
87+
$blockArguments = ['data' =>
88+
['logoPathResolver' => $this->objectManager->get(LogoPathResolverDefault::class)]
89+
];
90+
/** @var Logo $block */
91+
$block = $this->objectManager->create(LayoutInterface::class)
92+
->createBlock(Logo::class, 'logo', $blockArguments);
93+
$this->assertSame($host . $defaultPath, $block->getLogoSrc());
94+
$blockArguments = ['data' =>
95+
['logoPathResolver' => $this->objectManager->get(LogoPathResolverSales::class)]
96+
];
97+
/** @var Logo $block */
98+
$block = $this->objectManager->create(LayoutInterface::class)
99+
->createBlock(Logo::class, 'logo', $blockArguments);
100+
$this->assertSame($host . $defaultPath, $block->getLogoSrc());
101+
$this->mediaDirectory->delete($defaultPath);
102+
}
74103
}

0 commit comments

Comments
 (0)