|
| 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 | +} |
0 commit comments