Skip to content

Commit 9181adc

Browse files
committed
#24730: codereview fixes
Move Custom Logo file getter to separate service class
1 parent 2389da7 commit 9181adc

File tree

3 files changed

+86
-53
lines changed

3 files changed

+86
-53
lines changed

app/code/Magento/Sales/Helper/Invoice/Logo.php

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\Model\Order\Invoice;
9+
10+
use Magento\Store\Model\ScopeInterface;
11+
use Magento\Framework\UrlInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
14+
/**
15+
* Get Custom Logo File for Invoice HTML print
16+
*/
17+
class GetLogoFile
18+
{
19+
private const XML_PATH_SALES_IDENTITY_LOGO_HTML = 'sales/identity/logo_html';
20+
private const LOGO_BASE_DIR = 'sales/store/logo_html/';
21+
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
private $scopeConfig;
26+
27+
/**
28+
* @var UrlInterface
29+
*/
30+
private $urlBuilder;
31+
32+
/**
33+
* @param ScopeConfigInterface $scopeConfig
34+
* @param UrlInterface $urlBuilder
35+
*/
36+
public function __construct(
37+
ScopeConfigInterface $scopeConfig,
38+
UrlInterface $urlBuilder
39+
) {
40+
$this->scopeConfig = $scopeConfig;
41+
$this->urlBuilder = $urlBuilder;
42+
}
43+
44+
/**
45+
* Return Custom Invoice Logo file url if configured in admin
46+
*
47+
* @return string|null
48+
*/
49+
public function execute(): ?string
50+
{
51+
$result = null;
52+
53+
$invoiceLogoPath = $this->getIdentityLogoHtml();
54+
if ($invoiceLogoPath) {
55+
$mediaBaseUrl = $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]);
56+
$result = sprintf('%s%s%s', $mediaBaseUrl, $this->getLogoBaseDir(), $invoiceLogoPath);
57+
}
58+
59+
return $result;
60+
}
61+
62+
/**
63+
* Get base directory for Custom Invoice Logo
64+
*
65+
* @return string
66+
*/
67+
private function getLogoBaseDir(): string
68+
{
69+
return self::LOGO_BASE_DIR;
70+
}
71+
72+
/**
73+
* Get Admin Configuration for Invoice Logo HTML
74+
*
75+
* @return null|string
76+
*/
77+
private function getIdentityLogoHtml(): ?string
78+
{
79+
return $this->scopeConfig->getValue(
80+
self::XML_PATH_SALES_IDENTITY_LOGO_HTML,
81+
ScopeInterface::SCOPE_STORE,
82+
null
83+
);
84+
}
85+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<referenceContainer name="header-wrapper">
1515
<referenceBlock name="logo">
1616
<arguments>
17-
<argument name="logo_src" xsi:type="helper" helper="Magento\Sales\Helper\Invoice\Logo::getLogoFile"/>
17+
<argument name="logo_src" xsi:type="helper" helper="Magento\Sales\Model\Order\Invoice\GetLogoFile::execute"/>
1818
</arguments>
1919
</referenceBlock>
2020
</referenceContainer>

0 commit comments

Comments
 (0)