Skip to content

Commit 4531c76

Browse files
committed
MC-38834: Uploading a new logo for print on Logo for HTML Print View settings does not reflect on frontend my account order
1 parent ad29452 commit 4531c76

File tree

11 files changed

+253
-11
lines changed

11 files changed

+253
-11
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\ViewModel\Header;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface;
13+
use Magento\Framework\View\Element\Block\ArgumentInterface;
14+
use Magento\Sales\Model\Order;
15+
use Magento\Framework\Registry;
16+
17+
/**
18+
* Class for resolving logo path
19+
*/
20+
class LogoPathResolver implements LogoPathResolverInterface, ArgumentInterface
21+
{
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
private $scopeConfig;
26+
27+
/**
28+
* Core registry
29+
*
30+
* @var Registry
31+
*/
32+
private $coreRegistry;
33+
34+
/**
35+
* @param ScopeConfigInterface $scopeConfig
36+
* @param Registry $registry
37+
*/
38+
public function __construct(
39+
ScopeConfigInterface $scopeConfig,
40+
Registry $registry
41+
) {
42+
$this->scopeConfig = $scopeConfig;
43+
$this->coreRegistry = $registry;
44+
}
45+
46+
/**
47+
* Return logo image path
48+
*
49+
* @return string|null
50+
*/
51+
public function getPath(): ?string
52+
{
53+
$path = null;
54+
$storeId = null;
55+
$order = $this->coreRegistry->registry('current_order');
56+
if ($order instanceof Order) {
57+
$storeId = $order->getStoreId();
58+
}
59+
$storeLogoPath = $this->scopeConfig->getValue(
60+
'sales/identity/logo_html',
61+
ScopeInterface::SCOPE_STORE,
62+
$storeId
63+
);
64+
if ($storeLogoPath !== null) {
65+
$path = 'sales/store/logo_html/' . $storeLogoPath;
66+
}
67+
return $path;
68+
}
69+
}

app/code/Magento/Sales/view/frontend/layout/sales_order_print.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@
4444
<block class="Magento\Sales\Block\Order\Info" as="sales.order.print.info" name="sales.order.print.info" template="Magento_Sales::order/info.phtml"/>
4545
</referenceContainer>
4646
<block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
47+
<referenceBlock name="logo">
48+
<arguments>
49+
<argument name="logoPathResolver" xsi:type="object">Magento\Sales\ViewModel\Header\LogoPathResolver</argument>
50+
</arguments>
51+
</referenceBlock>
4752
</body>
4853
</page>

app/code/Magento/Sales/view/frontend/layout/sales_order_printcreditmemo.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
</block>
2929
</referenceContainer>
3030
<block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
31+
<referenceBlock name="logo">
32+
<arguments>
33+
<argument name="logoPathResolver" xsi:type="object">Magento\Sales\ViewModel\Header\LogoPathResolver</argument>
34+
</arguments>
35+
</referenceBlock>
3136
</body>
3237
</page>

app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@
3535
</block>
3636
</referenceContainer>
3737
<block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
38+
<referenceBlock name="logo">
39+
<arguments>
40+
<argument name="logoPathResolver" xsi:type="object">Magento\Sales\ViewModel\Header\LogoPathResolver</argument>
41+
</arguments>
42+
</referenceBlock>
3843
</body>
3944
</page>

app/code/Magento/Sales/view/frontend/layout/sales_order_printshipment.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@
2020
</block>
2121
</referenceContainer>
2222
<block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
23+
<referenceBlock name="logo">
24+
<arguments>
25+
<argument name="logoPathResolver" xsi:type="object">Magento\Sales\ViewModel\Header\LogoPathResolver</argument>
26+
</arguments>
27+
</referenceBlock>
2328
</body>
2429
</page>

app/code/Magento/Theme/Block/Html/Header/Logo.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Theme\Block\Html\Header;
88

9+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface;
10+
911
/**
1012
* Logo page header block
1113
*
@@ -124,16 +126,16 @@ public function getLogoHeight()
124126
*/
125127
protected function _getLogoUrl()
126128
{
127-
$folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR;
128-
$storeLogoPath = $this->_scopeConfig->getValue(
129-
'design/header/logo_src',
130-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
131-
);
132-
$path = $folderName . '/' . $storeLogoPath;
129+
$path = null;
130+
/** @var LogoPathResolverInterface $logoPathResolver */
131+
$logoPathResolver = $this->getData('logoPathResolver');
132+
if ($logoPathResolver instanceof LogoPathResolverInterface) {
133+
$path = $logoPathResolver->getPath();
134+
}
133135
$logoUrl = $this->_urlBuilder
134136
->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path;
135137

136-
if ($storeLogoPath !== null && $this->_isFile($path)) {
138+
if ($path !== null && $this->_isFile($path)) {
137139
$url = $logoUrl;
138140
} elseif ($this->getLogoFile()) {
139141
$url = $this->getViewFileUrl($this->getLogoFile());

app/code/Magento/Theme/Test/Unit/Block/Html/Header/LogoTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Theme\Test\Unit\Block\Html\Header;
99

10+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolverInterface;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\Directory\Read;
@@ -25,11 +26,11 @@ public function testGetLogoSrc()
2526
{
2627
$filesystem = $this->createMock(Filesystem::class);
2728
$mediaDirectory = $this->createMock(Read::class);
28-
$scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
29+
$logoPathResolver = $this->getMockForAbstractClass(LogoPathResolverInterface::class);
2930

3031
$urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);
3132

32-
$scopeConfig->expects($this->once())->method('getValue')->willReturn('default/image.gif');
33+
$logoPathResolver->expects($this->once())->method('getPath')->willReturn('logo/default/image.gif');
3334
$urlBuilder->expects(
3435
$this->once()
3536
)->method(
@@ -46,7 +47,7 @@ public function testGetLogoSrc()
4647
$objectManager = new ObjectManager($this);
4748

4849
$arguments = [
49-
'scopeConfig' => $scopeConfig,
50+
'data' => ['logoPathResolver' => $logoPathResolver],
5051
'urlBuilder' => $urlBuilder,
5152
'fileStorageHelper' => $helper,
5253
'filesystem' => $filesystem,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Theme\ViewModel\Block\Html\Header;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Config\Model\Config\Backend\Image\Logo;
12+
use Magento\Store\Model\ScopeInterface;
13+
use Magento\Framework\View\Element\Block\ArgumentInterface;
14+
15+
/**
16+
* Class for resolving logo path
17+
*/
18+
class LogoPathResolver implements LogoPathResolverInterface, ArgumentInterface
19+
{
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private $scopeConfig;
24+
25+
/**
26+
* @param ScopeConfigInterface $scopeConfig
27+
*/
28+
public function __construct(
29+
ScopeConfigInterface $scopeConfig
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
}
33+
34+
/**
35+
* Return logo image path
36+
*
37+
* @return string|null
38+
*/
39+
public function getPath(): ?string
40+
{
41+
$path = null;
42+
$storeLogoPath = $this->scopeConfig->getValue(
43+
'design/header/logo_src',
44+
ScopeInterface::SCOPE_STORE
45+
);
46+
if ($storeLogoPath !== null) {
47+
$path = Logo::UPLOAD_DIR . '/' . $storeLogoPath;
48+
}
49+
return $path;
50+
}
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Theme\ViewModel\Block\Html\Header;
9+
10+
/**
11+
* Interface for resolving logo path
12+
*/
13+
interface LogoPathResolverInterface
14+
{
15+
/**
16+
* Return logo image path
17+
*
18+
* @return null|string
19+
*/
20+
public function getPath(): ?string;
21+
}

app/code/Magento/Theme/view/frontend/layout/default.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
</container>
5252
</container>
5353
<container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content">
54-
<block class="Magento\Theme\Block\Html\Header\Logo" name="logo"/>
54+
<block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
55+
<arguments>
56+
<argument name="logoPathResolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver</argument>
57+
</arguments>
58+
</block>
5559
</container>
5660
</referenceContainer>
5761
<referenceContainer name="page.top">
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Block\Order\PrintOrder;
7+
8+
use Magento\Framework\View\LayoutInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Framework\App\State;
11+
use Magento\Theme\Block\Html\Header\Logo;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver as LogoPathResolverDefault;
17+
use Magento\Sales\ViewModel\Header\LogoPathResolver as LogoPathResolverSales;
18+
use \PHPUnit\Framework\TestCase;
19+
20+
class LogoTest extends TestCase
21+
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
/**
28+
* @var WriteInterface
29+
*/
30+
private $mediaDirectory;
31+
32+
protected function setUp(): void
33+
{
34+
$this->objectManager = Bootstrap::getObjectManager();
35+
$filesystem = $this->objectManager->get(Filesystem::class);
36+
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
37+
$this->objectManager->get(State::class)
38+
->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
39+
Bootstrap::getInstance()
40+
->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
41+
}
42+
43+
/**
44+
* @magentoConfigFixture default_store design/header/logo_src default/logo.jpg
45+
* @magentoConfigFixture default_store sales/identity/logo_html default/logo_sales.jpg
46+
* @throws \Magento\Framework\Exception\FileSystemException
47+
*/
48+
public function testGetLogoSrc(): void
49+
{
50+
$host = 'http://localhost/media/';
51+
$defaultLogoFile= 'logo.jpg';
52+
$defaultPath = 'logo/default/' . $defaultLogoFile;
53+
$salesLogoFile = 'logo_sales.jpg';
54+
$salesPath = 'sales/store/logo_html/default/' . $salesLogoFile;
55+
$this->mediaDirectory->writeFile($defaultPath, '');
56+
$this->mediaDirectory->writeFile($salesPath, '');
57+
$blockArguments = ['data' =>
58+
['logoPathResolver' => $this->objectManager->get(LogoPathResolverDefault::class)]
59+
];
60+
/** @var Logo $block */
61+
$block = $this->objectManager->create(LayoutInterface::class)
62+
->createBlock(Logo::class, 'logo', $blockArguments);
63+
$this->assertSame($host . $defaultPath, $block->getLogoSrc());
64+
$blockArguments = ['data' =>
65+
['logoPathResolver' => $this->objectManager->get(LogoPathResolverSales::class)]
66+
];
67+
/** @var Logo $block */
68+
$block = $this->objectManager->create(LayoutInterface::class)
69+
->createBlock(Logo::class, 'logo', $blockArguments);
70+
$this->assertSame($host . $salesPath, $block->getLogoSrc());
71+
$this->mediaDirectory->delete($defaultPath);
72+
$this->mediaDirectory->delete($salesPath);
73+
}
74+
}

0 commit comments

Comments
 (0)