Skip to content

magento/magento2#24730: Fix Frontend Invoice PDF configured Logo image #30632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 13, 2020
Merged
52 changes: 52 additions & 0 deletions app/code/Magento/Sales/Helper/Invoice/Logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Magento\Sales\Helper\Invoice;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;

class Logo extends AbstractHelper
{
const XML_PATH_SALES_IDENTITY_LOGO_HTML = 'sales/identity/logo_html';

protected $logoBaseDir = 'sales/store/logo_html/';

/**
* @return string|null
*/
public function getLogoFile()
{
$result = null;

$invoiceLogoPath = $this->getIdentityLogoHtml();
if ($invoiceLogoPath) {
$result = $this->_urlBuilder->getBaseUrl(
['_type' => UrlInterface::URL_TYPE_MEDIA]
) . $this->getLogoBaseDir() . $invoiceLogoPath;
}

return $result;
}

/**
* @return string
*/
public function getLogoBaseDir()
{
return $this->logoBaseDir;
}

/**
* @param null|int|string $store
* @return mixed
*/
public function getIdentityLogoHtml($store = null)
{
return $this->scopeConfig->getValue(
self::XML_PATH_SALES_IDENTITY_LOGO_HTML,
ScopeInterface::SCOPE_STORE,
$store
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<update handle="print" />
<body>
<attribute name="class" value="account"/>
<referenceContainer name="header-wrapper">
<referenceBlock name="logo">
<arguments>
<argument name="logo_src" xsi:type="helper" helper="Magento\Sales\Helper\Invoice\Logo::getLogoFile"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change xsi:type, I believe it should be "object" instead of "helper"
Also for block it's better to use ViewModel

Copy link
Contributor Author

@mozok mozok Oct 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I rely on check in original Block class
\Magento\Theme\Block\Html\Header\Logo

public function getLogoSrc()
{
    if (empty($this->_data['logo_src'])) {
        $this->_data['logo_src'] = $this->_getLogoUrl();
    }
    return $this->_data['logo_src'];
}

So I want to inject result of my service class execution into 'logo_src' argument just in one layout.
I assume, that give me opportunity to change logo for one layout, and not modify original template/block class.

</arguments>
</referenceBlock>
</referenceContainer>
<referenceContainer name="page.main.title">
<block class="Magento\Sales\Block\Order\PrintOrder\Invoice" name="order.status" template="Magento_Sales::order/order_status.phtml" />
<block class="Magento\Sales\Block\Order\PrintOrder\Invoice" name="order.date" template="Magento_Sales::order/order_date.phtml" />
Expand Down