From 2389da7df17a410deefac9d1f609da78f57c95d8 Mon Sep 17 00:00:00 2001 From: mozokevgen Date: Fri, 23 Oct 2020 22:38:28 +0300 Subject: [PATCH 1/5] magento/magento2#24730: Fix Frontend Invoice PDF configured Logo image --- .../Magento/Sales/Helper/Invoice/Logo.php | 52 +++++++++++++++++++ .../layout/sales_order_printinvoice.xml | 7 +++ 2 files changed, 59 insertions(+) create mode 100644 app/code/Magento/Sales/Helper/Invoice/Logo.php diff --git a/app/code/Magento/Sales/Helper/Invoice/Logo.php b/app/code/Magento/Sales/Helper/Invoice/Logo.php new file mode 100644 index 0000000000000..1e133e9546618 --- /dev/null +++ b/app/code/Magento/Sales/Helper/Invoice/Logo.php @@ -0,0 +1,52 @@ +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 + ); + } +} diff --git a/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml b/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml index 3e33f050cb0e7..0f4a557b992db 100644 --- a/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml +++ b/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml @@ -11,6 +11,13 @@ + + + + + + + From 9181adcefb3ae641d95e0a28fd99179b17d75aec Mon Sep 17 00:00:00 2001 From: mozokevgen Date: Sat, 24 Oct 2020 07:49:18 +0300 Subject: [PATCH 2/5] magento/magento2#24730: codereview fixes Move Custom Logo file getter to separate service class --- .../Magento/Sales/Helper/Invoice/Logo.php | 52 ------------ .../Sales/Model/Order/Invoice/GetLogoFile.php | 85 +++++++++++++++++++ .../layout/sales_order_printinvoice.xml | 2 +- 3 files changed, 86 insertions(+), 53 deletions(-) delete mode 100644 app/code/Magento/Sales/Helper/Invoice/Logo.php create mode 100644 app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php diff --git a/app/code/Magento/Sales/Helper/Invoice/Logo.php b/app/code/Magento/Sales/Helper/Invoice/Logo.php deleted file mode 100644 index 1e133e9546618..0000000000000 --- a/app/code/Magento/Sales/Helper/Invoice/Logo.php +++ /dev/null @@ -1,52 +0,0 @@ -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 - ); - } -} diff --git a/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php new file mode 100644 index 0000000000000..a48b5b6b1192e --- /dev/null +++ b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php @@ -0,0 +1,85 @@ +scopeConfig = $scopeConfig; + $this->urlBuilder = $urlBuilder; + } + + /** + * Return Custom Invoice Logo file url if configured in admin + * + * @return string|null + */ + public function execute(): ?string + { + $result = null; + + $invoiceLogoPath = $this->getIdentityLogoHtml(); + if ($invoiceLogoPath) { + $mediaBaseUrl = $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]); + $result = sprintf('%s%s%s', $mediaBaseUrl, $this->getLogoBaseDir(), $invoiceLogoPath); + } + + return $result; + } + + /** + * Get base directory for Custom Invoice Logo + * + * @return string + */ + private function getLogoBaseDir(): string + { + return self::LOGO_BASE_DIR; + } + + /** + * Get Admin Configuration for Invoice Logo HTML + * + * @return null|string + */ + private function getIdentityLogoHtml(): ?string + { + return $this->scopeConfig->getValue( + self::XML_PATH_SALES_IDENTITY_LOGO_HTML, + ScopeInterface::SCOPE_STORE, + null + ); + } +} diff --git a/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml b/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml index 0f4a557b992db..0272286696e24 100644 --- a/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml +++ b/app/code/Magento/Sales/view/frontend/layout/sales_order_printinvoice.xml @@ -14,7 +14,7 @@ - + From 7b7b83aa4cf37bda03c7fb48b6a5184edd375564 Mon Sep 17 00:00:00 2001 From: mozokevgen Date: Sat, 24 Oct 2020 08:24:27 +0300 Subject: [PATCH 3/5] magento/magento2#24730: codereview fixes simplify execute method --- .../Sales/Model/Order/Invoice/GetLogoFile.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php index a48b5b6b1192e..0d7edb8ef9622 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php +++ b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php @@ -48,15 +48,17 @@ public function __construct( */ public function execute(): ?string { - $result = null; - $invoiceLogoPath = $this->getIdentityLogoHtml(); - if ($invoiceLogoPath) { - $mediaBaseUrl = $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]); - $result = sprintf('%s%s%s', $mediaBaseUrl, $this->getLogoBaseDir(), $invoiceLogoPath); + if (!$invoiceLogoPath) { + return null; } - return $result; + return sprintf( + "%s%s%s", + $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]), + $this->getLogoBaseDir(), + $invoiceLogoPath + ); } /** From 182a65c06b1d72a8f248b5787b6993f156d2fe00 Mon Sep 17 00:00:00 2001 From: mozokevgen Date: Sat, 24 Oct 2020 13:05:01 +0300 Subject: [PATCH 4/5] magento/magento2#24730: Add integration test for Invoice GetLogoFile service class --- .../Model/Order/Invoice/GetLogoFileTest.php | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Sales/Model/Order/Invoice/GetLogoFileTest.php diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Invoice/GetLogoFileTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Invoice/GetLogoFileTest.php new file mode 100644 index 0000000000000..1e6341187b216 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Invoice/GetLogoFileTest.php @@ -0,0 +1,76 @@ +objectManager = Bootstrap::getObjectManager(); + $this->scopeConfig = $this->objectManager->get(MutableScopeConfigInterface::class); + $this->getLogoFile = $this->objectManager->get(GetLogoFile::class); + } + + /** + * Check that GetLogoFile return image after Admin configuration is changed + * + * @return void + */ + public function testExecute(): void + { + $this->assertNull($this->getLogoFile->execute()); + + $this->applyImage(); + + $this->assertIsString($this->getLogoFile->execute()); + $this->assertStringContainsString(self::DUMP_IMAGE, $this->getLogoFile->execute()); + } + + /** + * Set Invoice Custom Logo HTML Image configuration + * + * @return void + */ + private function applyImage(): void + { + $this->scopeConfig->setValue( + self::XML_PATH_SALES_IDENTITY_LOGO_HTML, + self::DUMP_IMAGE, + ScopeInterface::SCOPE_STORE + ); + } +} From 65bb09577438f4ed028e732e192ff911690c244f Mon Sep 17 00:00:00 2001 From: mozokevgen Date: Mon, 26 Oct 2020 18:41:58 +0200 Subject: [PATCH 5/5] magento/magento2#24730: remove unnecessary private method --- .../Sales/Model/Order/Invoice/GetLogoFile.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php index 0d7edb8ef9622..eec3fcdd59092 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php +++ b/app/code/Magento/Sales/Model/Order/Invoice/GetLogoFile.php @@ -56,21 +56,11 @@ public function execute(): ?string return sprintf( "%s%s%s", $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]), - $this->getLogoBaseDir(), + self::LOGO_BASE_DIR, $invoiceLogoPath ); } - /** - * Get base directory for Custom Invoice Logo - * - * @return string - */ - private function getLogoBaseDir(): string - { - return self::LOGO_BASE_DIR; - } - /** * Get Admin Configuration for Invoice Logo HTML *