Skip to content

Commit 957eec3

Browse files
committed
#35952 Admin Users unable to change front-end Logo in Design Config when in Single Store Mode
- Fixed issue with logo in single store mode for Theme viewmodel - Fixed issue with logo in single store mode for Sales viewmodel
1 parent bcb0fea commit 957eec3

File tree

4 files changed

+285
-3
lines changed

4 files changed

+285
-3
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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\Test\Unit\ViewModel\Header;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\Registry;
12+
use Magento\Sales\Model\Order;
13+
use Magento\Sales\ViewModel\Header\LogoPathResolver;
14+
use Magento\Store\Model\ScopeInterface;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test logo path resolver view model
20+
*/
21+
class LogoPathResolverTest extends TestCase
22+
{
23+
/**
24+
* @var ScopeConfigInterface|MockObject
25+
*/
26+
private $scopeConfig;
27+
28+
/**
29+
* @var LogoPathResolver
30+
*/
31+
private $model;
32+
33+
/**
34+
* Test for case when app in single store mode
35+
* and logo path is defined in config
36+
* @return void
37+
*/
38+
public function testGetPathWhenInSingleStoreModeAndSalesLogoPathNotNull(): void
39+
{
40+
$this->scopeConfig->method('getValue')
41+
->withConsecutive(
42+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
43+
['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1]
44+
)
45+
->willReturn(
46+
"1",
47+
'sales_identity_logo_html_value'
48+
);
49+
$valueForAssert = $this->model->getPath();
50+
$this->assertEquals('sales/store/logo_html/sales_identity_logo_html_value', $valueForAssert);
51+
$this->assertNotNull($valueForAssert);
52+
}
53+
54+
/**
55+
* Test for case when app in single store mode
56+
* and logo path is not defined in config
57+
* and header logo path is defined in config
58+
* @return void
59+
*/
60+
public function testGetPathWhenInSingleStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNotNull(): void
61+
{
62+
$this->scopeConfig->method('getValue')
63+
->withConsecutive(
64+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
65+
['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1],
66+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1]
67+
)
68+
->willReturn('1', null, 'SingleStore.png');
69+
$valueForAssert = $this->model->getPath();
70+
$this->assertEquals('logo/SingleStore.png', $valueForAssert);
71+
$this->assertNotNull($valueForAssert);
72+
}
73+
74+
/**
75+
* Test for case when app in single store mode
76+
* and logo path is not defined in config
77+
* and header logo path is not defined in config
78+
* @return void
79+
*/
80+
public function testGetPathWhenInSingleStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNull(): void
81+
{
82+
$this->scopeConfig->method('getValue')
83+
->withConsecutive(
84+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
85+
['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1],
86+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1]
87+
)
88+
->willReturn('1', null, null);
89+
$valueForAssert = $this->model->getPath();
90+
$this->assertNull($valueForAssert);
91+
}
92+
93+
/**
94+
* Test for case when app in multi store mode
95+
* and logo path is defined in config
96+
* @return void
97+
*/
98+
public function testGetPathWhenInMultiStoreModeAndPathNotNull(): void
99+
{
100+
$this->scopeConfig->method('getValue')
101+
->withConsecutive(
102+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
103+
['sales/identity/logo_html', ScopeInterface::SCOPE_STORE, 1]
104+
)
105+
->willReturn('0', 'sales_identity_logo_html_value');
106+
$valueForAssert = $this->model->getPath();
107+
$this->assertEquals('sales/store/logo_html/sales_identity_logo_html_value', $valueForAssert);
108+
$this->assertNotNull($valueForAssert);
109+
}
110+
111+
/**
112+
* Test for case when app in single store mode
113+
* and logo path is not defined in config
114+
* and header logo path is not defined in config
115+
* @return void
116+
*/
117+
public function testGetPathWhenInMultiStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNull(): void
118+
{
119+
$this->scopeConfig->method('getValue')
120+
->withConsecutive(
121+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
122+
['sales/identity/logo_html', ScopeInterface::SCOPE_STORE, 1],
123+
['design/header/logo_src', ScopeInterface::SCOPE_STORE, 1]
124+
)
125+
->willReturn('0', null, null);
126+
$valueForAssert = $this->model->getPath();
127+
$this->assertNull($valueForAssert);
128+
}
129+
130+
/**
131+
* Test for case when app in single store mode
132+
* and logo path is not defined in config
133+
* and header logo path is defined in config
134+
* @return void
135+
*/
136+
public function testGetPathWhenInMultiStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNotNull(): void
137+
{
138+
$this->scopeConfig->method('getValue')
139+
->withConsecutive(
140+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
141+
['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1],
142+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1]
143+
)
144+
->willReturn('1', null, 'MultiStore.png');
145+
$valueForAssert = $this->model->getPath();
146+
$this->assertEquals('logo/MultiStore.png', $valueForAssert);
147+
$this->assertNotNull($valueForAssert);
148+
}
149+
150+
/**
151+
* @inheritdoc
152+
*/
153+
protected function setUp(): void
154+
{
155+
parent::setUp();
156+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
157+
$this->registry = $this->createMock(Registry::class);
158+
$orderMock = $this->createMock(Order::class);
159+
$orderMock->method('getStoreId')
160+
->willReturn(1);
161+
$this->registry->method('registry')
162+
->with('current_order')
163+
->willReturn($orderMock);
164+
$this->model = new LogoPathResolver($this->scopeConfig, $this->registry);
165+
}
166+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ public function getPath(): ?string
5454
if ($order instanceof Order) {
5555
$storeId = $order->getStoreId();
5656
}
57+
$scopeType = ScopeInterface::SCOPE_STORE;
58+
if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
59+
$scopeType = ScopeInterface::SCOPE_WEBSITE;
60+
}
5761
$salesLogoPath = $this->scopeConfig->getValue(
5862
'sales/identity/logo_html',
59-
ScopeInterface::SCOPE_STORE,
63+
$scopeType,
6064
$storeId
6165
);
6266

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

6771
$headerLogoPath = $this->scopeConfig->getValue(
6872
'design/header/logo_src',
69-
ScopeInterface::SCOPE_STORE,
73+
$scopeType,
7074
$storeId
7175
);
7276

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\Test\Unit\ViewModel\Block\Html\Header;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test logo path resolver view model
18+
*/
19+
class LogoPathResolverTest extends TestCase
20+
{
21+
/**
22+
* @var ScopeConfigInterface|MockObject
23+
*/
24+
private $scopeConfig;
25+
26+
/**
27+
* @var LogoPathResolver
28+
*/
29+
private $model;
30+
31+
/**
32+
* Test for case when app in single store mode
33+
* and logo path is defined in config
34+
* @return void
35+
*/
36+
public function testGetPathWhenInSingleStoreModeAndPathNotNull(): void
37+
{
38+
$this->scopeConfig->method('getValue')
39+
->withConsecutive(
40+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
41+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, null]
42+
)
43+
->willReturn('1', 'SingleStore.png');
44+
$valueForAssert = $this->model->getPath();
45+
$this->assertEquals('logo/SingleStore.png', $valueForAssert);
46+
$this->assertNotNull($valueForAssert);
47+
}
48+
49+
/**
50+
* Test for case when app in single store mode
51+
* and logo path is not defined in config
52+
* @return void
53+
*/
54+
public function testGetPathWhenInSingleStoreModeAndPathIsNull(): void
55+
{
56+
$this->scopeConfig->method('getValue')
57+
->withConsecutive(
58+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
59+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, null]
60+
)
61+
->willReturn('1', null);
62+
$this->assertNull($this->model->getPath());
63+
}
64+
65+
/**
66+
* Test for case when app in multi store mode
67+
* and logo path is defined in config
68+
* @return void
69+
*/
70+
public function testGetPathWhenInMultiStoreModeAndPathNotNull(): void
71+
{
72+
$this->scopeConfig->method('getValue')
73+
->withConsecutive(
74+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
75+
['design/header/logo_src', ScopeInterface::SCOPE_STORE, null]
76+
)
77+
->willReturn('0', 'MultiStore.png');
78+
$valueForAssert = $this->model->getPath();
79+
$this->assertEquals('logo/MultiStore.png', $valueForAssert);
80+
$this->assertNotNull($valueForAssert);
81+
}
82+
83+
/**
84+
* Test for case when app in multi store mode
85+
* and logo path is not defined in config
86+
* @return void
87+
*/
88+
public function testGetPathWhenInMultiStoreModeAndPathIsNull(): void
89+
{
90+
$this->scopeConfig->method('getValue')
91+
->withConsecutive(
92+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
93+
['design/header/logo_src', ScopeInterface::SCOPE_STORE, null]
94+
)
95+
->willReturn('0', null);
96+
$this->assertNull($this->model->getPath());
97+
}
98+
99+
/**
100+
* @inheritdoc
101+
*/
102+
protected function setUp(): void
103+
{
104+
parent::setUp();
105+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
106+
$this->model = new LogoPathResolver($this->scopeConfig);
107+
}
108+
}

app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ public function __construct(
3939
public function getPath(): ?string
4040
{
4141
$path = null;
42+
$scopeType = ScopeInterface::SCOPE_STORE;
43+
if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
44+
$scopeType = ScopeInterface::SCOPE_WEBSITE;
45+
}
4246
$storeLogoPath = $this->scopeConfig->getValue(
4347
'design/header/logo_src',
44-
ScopeInterface::SCOPE_STORE
48+
$scopeType
4549
);
4650
if ($storeLogoPath !== null) {
4751
$path = Logo::UPLOAD_DIR . '/' . $storeLogoPath;

0 commit comments

Comments
 (0)