├── .gitattributes ├── .github └── workflows │ ├── ci.yml │ └── performance │ └── docker-compose.yml ├── .gitignore ├── CHANGELOG.md ├── Jenkinsfile ├── captainhook.json ├── composer.json ├── phpunit.xml.dist ├── project.properties ├── src ├── Block │ └── Config │ │ └── PrintOrderPdf.php ├── LICENSE.txt ├── Model │ ├── Api │ │ ├── AttachmentContainerInterface.php │ │ ├── AttachmentInterface.php │ │ ├── MailProcessorInterface.php │ │ └── PdfRendererInterface.php │ ├── Attachment.php │ ├── AttachmentContainer.php │ ├── ContentAttacher.php │ ├── EmailEventDispatcher.php │ ├── EmailIdentifier.php │ ├── EmailType.php │ ├── MailProcessor.php │ ├── NextEmailInfo.php │ ├── NoneRenderer.php │ ├── PdfRenderer.php │ └── TermsAndConditionsAttacher.php ├── Observer │ ├── AbstractObserver.php │ ├── AbstractSendCreditmemoObserver.php │ ├── AbstractSendInvoiceObserver.php │ ├── AbstractSendInvoiceShipmentObserver.php │ ├── AbstractSendOrderObserver.php │ ├── AbstractSendShipmentObserver.php │ ├── BeforeSendCreditmemoCommentObserver.php │ ├── BeforeSendCreditmemoObserver.php │ ├── BeforeSendInvoiceCommentObserver.php │ ├── BeforeSendInvoiceObserver.php │ ├── BeforeSendInvoiceShipmentCommentObserver.php │ ├── BeforeSendInvoiceShipmentObserver.php │ ├── BeforeSendOrderCommentObserver.php │ ├── BeforeSendOrderObserver.php │ ├── BeforeSendShipmentCommentObserver.php │ └── BeforeSendShipmentObserver.php ├── Plugin │ ├── MimeMessageFactory.php │ ├── Transport.php │ └── TransportBuilder.php ├── composer.json ├── etc │ ├── adminhtml │ │ └── system.xml │ ├── config.xml │ ├── di.xml │ ├── events.xml │ └── module.xml ├── i18n │ ├── ar_SA.csv │ ├── ca_ES.csv │ ├── cs_CZ.csv │ ├── da_DK.csv │ ├── de_DE.csv │ ├── en_US.csv │ ├── es_ES.csv │ ├── et_EE.csv │ ├── fa_IR.csv │ ├── fi_FI.csv │ ├── fr_FR.csv │ ├── gr_GR.csv │ ├── he_IL.csv │ ├── hr_HR.csv │ ├── hu_HU.csv │ ├── it_IT.csv │ ├── ja_JP.csv │ ├── ko_KR.csv │ ├── lt_LT.csv │ ├── lv_LV.csv │ ├── nb_NO.csv │ ├── nl_NL.csv │ ├── no_NO.csv │ ├── pl_PL.csv │ ├── pt_BR.csv │ ├── ro_RO.csv │ ├── ru_RU.csv │ ├── sk_SK.csv │ ├── sl_SI.csv │ ├── sv_SE.csv │ ├── th_TH.csv │ ├── tr_TR.csv │ └── zh_CN.csv └── registration.php └── tests ├── acceptance └── Mftf │ ├── ActionGroup │ └── AdminConfigureFoomanEmailAttachmentsActionGroup.xml │ ├── Page │ └── AdminEmailAttachmentsConfigurationPage.xml │ ├── Section │ └── AdminFoomanEmailAttachmentsSettingsSection.xml │ └── Test │ └── AdminCheckInvoiceEmailSendTest.xml ├── integration └── testsuite │ └── Fooman │ └── EmailAttachments │ ├── Observer │ ├── BeforeSendCreditmemoCommentObserverTest.php │ ├── BeforeSendCreditmemoObserverTest.php │ ├── BeforeSendInvoiceCommentObserverTest.php │ ├── BeforeSendInvoiceObserverTest.php │ ├── BeforeSendOrderCommentObserverTest.php │ ├── BeforeSendOrderObserverTest.php │ ├── BeforeSendShipmentCommentObserverTest.php │ ├── BeforeSendShipmentObserverTest.php │ └── Common.php │ ├── TransportBuilder.php │ └── _files │ └── agreement_active_with_text_content.php └── unit ├── bootstrap.php └── testsuite └── Fooman └── EmailAttachments └── UnitTest └── Model ├── AttachmentContainerTest.php └── AttachmentTest.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Autodetect text files 2 | * text=auto 3 | 4 | *.csv eol=lf 5 | *.php eol=lf -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continous Integration 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | performance: 6 | name: M2 Performance Testing 7 | runs-on: ubuntu-latest 8 | env: 9 | DOCKER_COMPOSE_FILE: "./extension/.github/workflows/performance/docker-compose.yml" 10 | EXTENSION_NAME: "Fooman_EmailAttachments" 11 | EXTENSION_PACKAGE_NAME: "fooman/emailattachments-implementation-m2" 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | name: Checkout files 16 | with: 17 | path: extension 18 | 19 | - name: Get composer cache directory 20 | id: composer-cache 21 | run: "echo \"::set-output name=dir::$(composer config cache-dir)\"" 22 | working-directory: ./extension 23 | 24 | - name: Cache dependencies 25 | uses: actions/cache@v1 26 | with: 27 | path: ${{ steps.composer-cache.outputs.dir }} 28 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: ${{ runner.os }}-composer- 30 | 31 | - name: Prepare ExtDN performance testing 32 | uses: extdn/github-actions-m2/magento-performance-setup@master 33 | env: 34 | BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} 35 | BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} 36 | BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} 37 | BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} 38 | 39 | - name: Install Magento 40 | run: >- 41 | docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} exec -T php-fpm 42 | bash -c 'cd /var/www/html/m2 && sudo chown www-data: -R /var/www/html/m2 && ls -al && id 43 | && php -f bin/magento setup:install --base-url=http://magento2.test/ --backend-frontname=admin --db-host=mysql --db-name=magento_performance_tests --db-user=root --db-password=123123q --admin-user=admin@example.com --admin-password=password1 --admin-email=admin@example.com --admin-firstname=firstname --admin-lastname=lastname' 44 | - name: Generate Performance Fixtures 45 | run: >- 46 | docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} exec -T php-fpm 47 | bash -c 'cd /var/www/html/m2 48 | && php -f bin/magento setup:performance:generate-fixtures setup/performance-toolkit/profiles/ce/small.xml 49 | && php -f bin/magento cache:enable 50 | && php -f bin/magento cache:disable block_html full_page' 51 | - name: Run Blackfire 52 | id: blackfire-baseline 53 | run: docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} run blackfire-agent blackfire --json curl http://magento2.test/category-1/category-1-1.html > ${{ github.workspace }}/baseline.json 54 | env: 55 | BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} 56 | BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} 57 | BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} 58 | BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} 59 | 60 | - name: Install Extension 61 | run: >- 62 | docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} exec -e EXTENSION_BRANCH=${GITHUB_REF#refs/heads/} -T php-fpm 63 | bash -c 'cd /var/www/html/m2 64 | && php -f vendor/composer/composer/bin/composer config repo.extension path /var/www/html/extension 65 | && php -f vendor/composer/composer/bin/composer require ${{ env.EXTENSION_PACKAGE_NAME }}:dev-$EXTENSION_BRANCH#${{ github.sha }} 66 | && php -f bin/magento module:enable ${{ env.EXTENSION_NAME }} 67 | && php -f bin/magento setup:upgrade 68 | && php -f bin/magento cache:enable 69 | && php -f bin/magento cache:disable block_html full_page' 70 | - name: Run Blackfire Again 71 | id: blackfire-after 72 | run: docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} run blackfire-agent blackfire --json curl http://magento2.test/category-1/category-1-1.html > ${{ github.workspace }}/after.json 73 | env: 74 | BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} 75 | BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} 76 | BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} 77 | BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} 78 | 79 | - name: Compare Performance Results 80 | uses: extdn/github-actions-m2/magento-performance-compare@master 81 | 82 | static: 83 | name: M2 Coding Standard 84 | runs-on: ubuntu-latest 85 | steps: 86 | - uses: actions/checkout@v2 87 | - uses: extdn/github-actions-m2/magento-coding-standard@master 88 | 89 | phpmd: 90 | name: M2 Mess Detector 91 | runs-on: ubuntu-latest 92 | steps: 93 | - uses: actions/checkout@v2 94 | - uses: extdn/github-actions-m2/magento-mess-detector@master 95 | 96 | phpstan: 97 | name: M2 PhpStan 98 | runs-on: ubuntu-latest 99 | steps: 100 | - uses: actions/checkout@v2 101 | - uses: extdn/github-actions-m2/magento-phpstan@master 102 | with: 103 | composer_name: fooman/emailattachments-implementation-m2 -------------------------------------------------------------------------------- /.github/workflows/performance/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | services: 3 | php-fpm: 4 | image: quay.io/warden/php-fpm:7.3-magento2 5 | volumes: 6 | - ${GITHUB_WORKSPACE}:/var/www/html 7 | networks: 8 | default: 9 | 10 | php-blackfire: 11 | image: quay.io/warden/php-fpm:7.3-magento2-blackfire 12 | volumes: 13 | - ${GITHUB_WORKSPACE}:/var/www/html 14 | networks: 15 | default: 16 | 17 | blackfire-agent: 18 | image: blackfire/blackfire:latest 19 | environment: 20 | - BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID} 21 | - BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN} 22 | - BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID} 23 | - BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN} 24 | networks: 25 | default: 26 | 27 | mysql: 28 | image: quay.io/warden/mysql:5.7 29 | environment: 30 | - MYSQL_ROOT_PASSWORD=123123q 31 | - MYSQL_DATABASE=magento_performance_tests 32 | ports: 33 | - 3306 34 | healthcheck: 35 | test: mysqladmin ping 36 | interval: 10s 37 | retries: 3 38 | networks: 39 | default: 40 | 41 | rabbitmq: 42 | image: quay.io/warden/rabbitmq:3.7 43 | ports: 44 | - 5672 45 | healthcheck: 46 | test: rabbitmqctl node_health_check 47 | interval: 10s 48 | retries: 3 49 | networks: 50 | default: 51 | 52 | nginx: 53 | networks: 54 | default: 55 | aliases: 56 | - magento2.test 57 | user: root 58 | volumes: 59 | - ${GITHUB_WORKSPACE}:/var/www/html 60 | image: quay.io/warden/nginx:1.17 61 | environment: 62 | - NGINX_ROOT=/var/www/html/m2 63 | - NGINX_PUBLIC=/pub 64 | - NGINX_TEMPLATE=magento2.conf 65 | ports: 66 | - 80:80 67 | 68 | networks: 69 | default: -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ^.idea/ 2 | ^vendor/ 3 | composer.lock 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [Unreleased] 4 | 5 | ## [107.5.2] - 2025-04-10 6 | ### Fixed 7 | - Adjust test output for mailpit response 8 | 9 | ## [107.5.1] - 2025-04-10 10 | ### Fixed 11 | - Rework extension to also support Symfony Mailer 12 | 13 | ## [107.5.0] - 2025-03-04 14 | ### Added 15 | - Support for Magento 2.4.8 16 | - Support for Php 8.4 17 | 18 | ## [107.4.0] - 2024-03-18 19 | ### Added 20 | - Support for Php 8.3 21 | ### Changed 22 | - Code style updates for newer Magento Coding Standard 23 | 24 | ## [107.3.0] - 2023-02-07 25 | ### Added 26 | - Support for Php 8.2 27 | 28 | ## [107.2.1] - 2022-01-30 29 | ### Added 30 | - Support for PHP 8.0 and 8.1 31 | 32 | ## [107.2.0] - 2021-09-08 33 | ### Changed 34 | - Switch to Laminas Mime package, minimum Magento version is now 2.3.5 35 | 36 | ## [107.1.1] - 2020-12-10 37 | ### Fixed 38 | - Don't send the same named attachment twice 39 | 40 | ## [107.1.0] - 2020-07-27 41 | ### Added 42 | - Support for PHP 7.4 43 | - Support for Magento 2.4.0 44 | ### Fixed 45 | - Mislabeled admin setting 46 | 47 | ## [107.0.1] - 2020-05-01 48 | ### Fixed 49 | - Reworked email identification to strictly cover supported types only 50 | 51 | ## [107.0.0] - 2020-01-21 52 | ### Added 53 | - Ability to attach invoices to the shipping confirmation email 54 | ### Changed 55 | - Model\Api\PdfRendererInterface getFileName method signature changed 56 | - Updated comments for latest Magento Coding Standards 57 | 58 | ## [106.0.0] - 2019-10-04 59 | ### Changed 60 | - Adjustments for new email handling in Magento 2.3.3 61 | Removed Plugin\TransportFactory with most functionality now handled by Plugin\MimeMessageFactory, 62 | Method signature changes for Model\EmailEventDispatcher 63 | - Use previous releases for earlier versions of Magento 64 | - Removed support for Php 7.0 65 | 66 | ## [105.1.1] - 2019-08-14 67 | ### Changed 68 | - Adjust for changed core behaviour around plain text emails 69 | 70 | ## [105.1.0] - 2019-06-26 71 | ### Added 72 | - AttachmentInterface::getFilename(true) now provides the base64 encoded name of the attachment 73 | - PHPStan to development tools 74 | ### Fixed 75 | - Some parameter type issues 76 | 77 | ## [105.0.8] - 2019-05-10 78 | ### Changed 79 | - Adopt latest Magento Coding Standards 80 | 81 | ## [105.0.7] - 2019-04-19 82 | ### Fixed 83 | - MFTF tweak if not run in isolation 84 | 85 | ## [105.0.6] - 2019-04-11 86 | ### Fixed 87 | - Reverse additional return types 88 | 89 | ## [105.0.5] - 2019-04-09 90 | ### Fixed 91 | - Reverse adding return types to maintain 2.2.8 compatibility 92 | 93 | ## [105.0.4] - 2019-03-27 94 | ### Added 95 | - Compatibility with Magento 2.2.8 96 | 97 | ## [105.0.3] - 2019-03-27 98 | ### Added 99 | - Initial MFTF acceptance test 100 | 101 | ## [105.0.2] - 2018-12-11 102 | ### Changed 103 | - Reverse 7.1 features as Magento Marketplace does not yet support it 104 | 105 | ## [105.0.1] - 2018-11-27 106 | ### Changed 107 | - Use newer php features (minimum 7.1) 108 | 109 | ## [105.0.0] - 2018-11-26 110 | ### Changed 111 | - Add compatibility with Magento 2.3.0 and handle upgrade of Zend_Mail, for earlier versions of Magento use 112 | previous versions 113 | Constructor change in Model\EmailEventDispatcher 114 | - explicitly state Zend\Mime dependency 115 | 116 | ## [104.0.4] - 2018-09-28 117 | ### Added 118 | - Ability to customise affect the final filename 119 | 120 | ## [104.0.3] - 2018-07-23 121 | ### Changed 122 | - Reorganised unit tests 123 | 124 | ## [104.0.2] - 2018-07-15 125 | ### Changed 126 | - Code Quality improvement - use class constants 127 | 128 | ## [104.0.1] - 2018-07-10 129 | ### Changed 130 | - Fixed integration tests 131 | 132 | ## [104.0.0] - 2018-06-25 133 | ### Changed 134 | - Major rewrite - removed all preferences, use plugins on TransportBuilder and TransportFactory instead 135 | 136 | ## [103.0.1] - 2018-03-20 137 | ### Changed 138 | - Adjusted tests to provide for Pdf Customiser transforming T&Cs to Pdfs 139 | 140 | ## [103.0.0] - 2018-03-15 141 | ### Changed 142 | - Package name renamed to fooman/emailattachments-implementation-m2, installation should be via metapackage fooman/emailattachments-m2 143 | - Increased version number by 100 to differentiate from metapackage 144 | - Moved attachment code into separate class 145 | Constructor change Observer\AbstractObserver 146 | - Attachments are also added to emails sent separately 147 | 148 | ## [2.1.0] - 2017-09-01 149 | ### Added 150 | - Support for PHP 7.1 151 | - Support for Magento 2.2.0 152 | 153 | ## [2.0.8] - 2017-06-02 154 | ### Fixed 155 | - Make CheckoutAgreements dependency explicit 156 | 157 | ## [2.0.7] - 2017-02-28 158 | ### Added 159 | - Ability for integration test to check for attachment name 160 | 161 | ## [2.0.6] - 2017-02-26 162 | ### Fixed 163 | - Translations of file names (thanks Manuel) 164 | 165 | ## [2.0.5] - 2016-09-22 166 | ### Added 167 | - Add note to "Attach Order as Pdf" that it requires the Print Order Pdf extension 168 | 169 | ## [2.0.4] - 2016-06-15 170 | ### Changed 171 | - Widen dependencies in preparation for Magento 2.1.0 172 | 173 | ## [2.0.3] - 2016-04-03 174 | ### Fixed 175 | - Add missing configuration setting for attaching T&Cs to shipping email 176 | 177 | ## [2.0.2] - 2016-04-01 178 | ### Changed 179 | - Release for Marketplace 180 | 181 | ## [2.0.1] - 2016-03-25 182 | ### Added 183 | - Integration tests now support Pdf Customiser supplied attachments 184 | 185 | ## [2.0.0] - 2016-01-21 186 | ### Changed 187 | - Change project folder structure to src/ and tests/ (not applicable for Marketplace version) 188 | 189 | ## [1.0.0] - 2015-11-29 190 | ### Added 191 | - Initial release for Magento 2 192 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | extPipeline {} -------------------------------------------------------------------------------- /captainhook.json: -------------------------------------------------------------------------------- 1 | { 2 | "commit-msg": { 3 | "enabled": false, 4 | "actions": [] 5 | }, 6 | "pre-push": { 7 | "enabled": false, 8 | "actions": [] 9 | }, 10 | "pre-commit": { 11 | "enabled": true, 12 | "actions": [ 13 | { 14 | "action": "\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting", 15 | "options": [], 16 | "conditions": [] 17 | }, 18 | { 19 | "action": "vendor/bin/phpunit", 20 | "options": [], 21 | "conditions": [] 22 | }, 23 | { 24 | "action": "vendor/bin/phpcs --standard=psr2 src", 25 | "options": [], 26 | "conditions": [] 27 | }, 28 | { 29 | "action": "vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../magento/php-compatibility-fork,../../phpcsstandards/phpcsutils && vendor/bin/phpcs --severity=6 -s --standard=Magento2 src", 30 | "options": [], 31 | "conditions": [] 32 | }, 33 | { 34 | "action": "vendor/bin/phpstan analyse src/ -l 1", 35 | "options": [], 36 | "conditions": [] 37 | } 38 | ] 39 | }, 40 | "prepare-commit-msg": { 41 | "enabled": false, 42 | "actions": [] 43 | }, 44 | "post-commit": { 45 | "enabled": false, 46 | "actions": [] 47 | }, 48 | "post-merge": { 49 | "enabled": false, 50 | "actions": [] 51 | }, 52 | "post-checkout": { 53 | "enabled": false, 54 | "actions": [] 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fooman/emailattachments-implementation-m2", 3 | "license": "OSL-3.0", 4 | "description": "Automatically attach pdf and terms and conditions documents to outgoing sales emails.", 5 | "type": "magento2-module", 6 | "version": "107.5.3", 7 | "autoload": { 8 | "psr-4": { 9 | "Fooman\\EmailAttachments\\": "src/" 10 | }, 11 | "files": [ 12 | "src/registration.php" 13 | ] 14 | }, 15 | "require": { 16 | "php": "~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0||~8.2.0||~8.3.0||~8.4.0", 17 | "magento/framework": "^102.0.5 || ^103.0.0", 18 | "magento/module-backend": "^101.0.0 || ^102.0.0", 19 | "magento/module-checkout-agreements": "^100.0.2", 20 | "magento/module-email": "^101.0.3", 21 | "magento/module-sales": "^102.0.0 || ^103.0.0" 22 | }, 23 | "require-dev": { 24 | "fooman/testing-and-quality-tools": "^1.0" 25 | }, 26 | "minimum-stability": "dev", 27 | "prefer-stable": true, 28 | "suggest": { 29 | "fooman/printorderpdf-m2": "Allows attaching the order confirmation pdf to the order confirmation email", 30 | "fooman/pdfcustomiser-m2": "Allows to easily customise the sales pdfs while also reducing file sizes " 31 | }, 32 | "config": { 33 | "sort-packages": true 34 | } 35 | } -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./tests/unit/testsuite/Fooman 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | composer.name = fooman/emailattachments-implementation-m2 2 | test.unit = true 3 | test.integration = true 4 | test.functional = false 5 | test.acceptance = true 6 | artifact.name = Fooman_EmailAttachmentsImplementation 7 | release-to-store = false 8 | release-shared-marketplace = true 9 | release-to-marketplace = false 10 | release-to-public-github = true 11 | supports-magento-ce-2.0 = false 12 | supports-magento-ce-2.1 = false 13 | supports-magento-ce-2.2 = false 14 | supports-magento-ce-2.3 = true 15 | supports-magento-ce-2.4 = true 16 | supports-magento-ee-2.0 = false 17 | supports-magento-ee-2.1 = false 18 | supports-magento-ee-2.2 = false 19 | supports-magento-ee-2.3 = false 20 | supports-magento-ee-2.4 = false -------------------------------------------------------------------------------- /src/Block/Config/PrintOrderPdf.php: -------------------------------------------------------------------------------- 1 | moduleList = $moduleList; 31 | parent::__construct($context, $data); 32 | } 33 | 34 | // phpcs:ignore PSR2.Methods.MethodDeclaration -- Magento 2 core use 35 | protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) 36 | { 37 | if ($this->moduleList->has('Fooman_PrintOrderPdf')) { 38 | return parent::_getElementHtml($element); 39 | } 40 | return (string)__( 41 | 'This functionality requires the Print Order Pdf extension.', 42 | self::EXT_URL 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Open Software License ("OSL") v. 3.0 3 | 4 | This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: 5 | 6 | Licensed under the Open Software License version 3.0 7 | 8 | 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 9 | 10 | 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 11 | 12 | 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 13 | 14 | 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; 15 | 16 | 4. to perform the Original Work publicly; and 17 | 18 | 5. to display the Original Work publicly. 19 | 20 | 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 21 | 22 | 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 23 | 24 | 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 25 | 26 | 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 27 | 28 | 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 29 | 30 | 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 31 | 32 | 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 33 | 34 | 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 35 | 36 | 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 37 | 38 | 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 39 | 40 | 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 41 | 42 | 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 43 | 44 | 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 45 | 46 | 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 47 | 48 | 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. -------------------------------------------------------------------------------- /src/Model/Api/AttachmentContainerInterface.php: -------------------------------------------------------------------------------- 1 | content = $content; 35 | $this->mimeType = $mimeType; 36 | $this->filename = $fileName; 37 | $this->disposition = $disposition; 38 | $this->encoding = $encoding; 39 | } 40 | 41 | /** 42 | * @return mixed 43 | */ 44 | public function getMimeType() 45 | { 46 | return $this->mimeType; 47 | } 48 | 49 | /** 50 | * @param bool $encoded 51 | * 52 | * @return mixed 53 | */ 54 | public function getFilename($encoded = false) 55 | { 56 | if ($encoded) { 57 | return sprintf('=?utf-8?B?%s?=', base64_encode($this->filename)); 58 | } 59 | return $this->filename; 60 | } 61 | 62 | /** 63 | * @return string 64 | */ 65 | public function getDisposition() 66 | { 67 | return $this->disposition; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getEncoding() 74 | { 75 | return $this->encoding; 76 | } 77 | 78 | /** 79 | * @return mixed 80 | */ 81 | public function getContent() 82 | { 83 | return $this->content; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Model/AttachmentContainer.php: -------------------------------------------------------------------------------- 1 | attachments); 23 | } 24 | 25 | /** 26 | * @param Api\AttachmentInterface $attachment 27 | */ 28 | public function addAttachment(Api\AttachmentInterface $attachment) 29 | { 30 | $dedupId = hash('sha256', $attachment->getFilename()); 31 | if (!isset($this->dedupIds[$dedupId])) { 32 | $this->attachments[] = $attachment; 33 | $this->dedupIds[$dedupId] = true; 34 | } 35 | } 36 | 37 | /** 38 | * @return array 39 | */ 40 | public function getAttachments() 41 | { 42 | return $this->attachments; 43 | } 44 | 45 | /** 46 | * @return void 47 | */ 48 | public function resetAttachments() 49 | { 50 | $this->attachments = []; 51 | $this->dedupIds = []; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Model/ContentAttacher.php: -------------------------------------------------------------------------------- 1 | attachmentFactory = $attachmentFactory; 27 | } 28 | 29 | public function addGeneric($content, $filename, $mimeType, ContainerInterface $attachmentContainer) 30 | { 31 | $attachment = $this->attachmentFactory->create( 32 | [ 33 | 'content' => $content, 34 | 'mimeType' => $mimeType, 35 | 'fileName' => $filename 36 | ] 37 | ); 38 | $attachmentContainer->addAttachment($attachment); 39 | } 40 | 41 | public function addPdf($pdfString, $pdfFilename, ContainerInterface $attachmentContainer) 42 | { 43 | $this->addGeneric($pdfString, $pdfFilename, self::MIME_PDF, $attachmentContainer); 44 | } 45 | 46 | public function addText($text, $filename, ContainerInterface $attachmentContainer) 47 | { 48 | $this->addGeneric($text, $filename, self::MIME_TXT, $attachmentContainer); 49 | } 50 | 51 | public function addHtml($html, $filename, ContainerInterface $attachmentContainer) 52 | { 53 | $this->addGeneric($html, $filename, self::MIME_HTML, $attachmentContainer); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Model/EmailEventDispatcher.php: -------------------------------------------------------------------------------- 1 | eventManager = $eventManager; 37 | $this->nextEmailInfo = $nextEmailInfo; 38 | $this->emailIdentifier = $emailIdentifier; 39 | } 40 | 41 | public function dispatch(Api\AttachmentContainerInterface $attachmentContainer) 42 | { 43 | if ($this->nextEmailInfo->getTemplateIdentifier()) { 44 | $this->determineEmailAndDispatch($attachmentContainer); 45 | $this->nextEmailInfo->reset(); 46 | } 47 | } 48 | 49 | public function determineEmailAndDispatch(Api\AttachmentContainerInterface $attachmentContainer) 50 | { 51 | $emailType = $this->emailIdentifier->getType($this->nextEmailInfo); 52 | if ($emailType->getType()) { 53 | $this->eventManager->dispatch( 54 | 'fooman_emailattachments_before_send_' . $emailType->getType(), 55 | [ 56 | 57 | 'attachment_container' => $attachmentContainer, 58 | $emailType->getVarCode() => $this->nextEmailInfo->getTemplateVars()[$emailType->getVarCode()] 59 | ] 60 | ); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Model/EmailIdentifier.php: -------------------------------------------------------------------------------- 1 | scopeConfig = $scopeConfig; 40 | $this->emailTypeFactory = $emailTypeFactory; 41 | } 42 | 43 | /** 44 | * If you want to identify additional email types add an afterGetType plugin to this method. 45 | * 46 | * The below class will then emit your custom event fooman_emailattachments_before_send_YOURTYPE 47 | * @see EmailEventDispatcher::determineEmailAndDispatch() 48 | * 49 | * @param NextEmailInfo $nextEmailInfo 50 | * 51 | * @return EmailType 52 | */ 53 | public function getType(NextEmailInfo $nextEmailInfo) 54 | { 55 | $type = false; 56 | $templateVars = $nextEmailInfo->getTemplateVars(); 57 | 58 | $varCode = $this->getMainEmailType($templateVars); 59 | if ($varCode) { 60 | $method = 'get' . ucfirst($varCode) . 'Email'; 61 | $type = $this->$method( 62 | $nextEmailInfo->getTemplateIdentifier(), 63 | $templateVars[$varCode]->getStoreId() 64 | ); 65 | } 66 | 67 | return $this->emailTypeFactory->create(['type' => $type, 'varCode' => $varCode]); 68 | } 69 | 70 | private function getMainEmailType($templateVars) 71 | { 72 | if (isset($templateVars['shipment']) && method_exists($templateVars['shipment'], 'getStoreId')) { 73 | return 'shipment'; 74 | } 75 | 76 | if (isset($templateVars['invoice']) && method_exists($templateVars['invoice'], 'getStoreId')) { 77 | return 'invoice'; 78 | } 79 | 80 | if (isset($templateVars['creditmemo']) && method_exists($templateVars['creditmemo'], 'getStoreId')) { 81 | return 'creditmemo'; 82 | } 83 | 84 | if (isset($templateVars['order']) && method_exists($templateVars['order'], 'getStoreId')) { 85 | return 'order'; 86 | } 87 | 88 | //Not an email we can identify 89 | return false; 90 | } 91 | 92 | private function doesTemplateIdMatchConfig( 93 | $templateIdentifier, 94 | $guestTemplateConfigPath, 95 | $customerTemplateConfigPath, 96 | $storeId 97 | ) { 98 | return $this->scopeConfig->getValue($guestTemplateConfigPath, ScopeInterface::SCOPE_STORE, $storeId) 99 | === $templateIdentifier 100 | || $this->scopeConfig->getValue($customerTemplateConfigPath, ScopeInterface::SCOPE_STORE, $storeId) 101 | === $templateIdentifier; 102 | } 103 | 104 | private function getShipmentEmail($templateIdentifier, $storeId) 105 | { 106 | if ($this->doesTemplateIdMatchConfig( 107 | $templateIdentifier, 108 | ShipmentIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 109 | ShipmentIdentity::XML_PATH_EMAIL_TEMPLATE, 110 | $storeId 111 | )) { 112 | return 'shipment'; 113 | } 114 | 115 | if ($this->doesTemplateIdMatchConfig( 116 | $templateIdentifier, 117 | ShipmentCommentIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 118 | ShipmentCommentIdentity::XML_PATH_EMAIL_TEMPLATE, 119 | $storeId 120 | )) { 121 | return 'shipment_comment'; 122 | } 123 | 124 | return false; 125 | } 126 | 127 | private function getInvoiceEmail($templateIdentifier, $storeId) 128 | { 129 | if ($this->doesTemplateIdMatchConfig( 130 | $templateIdentifier, 131 | InvoiceIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 132 | InvoiceIdentity::XML_PATH_EMAIL_TEMPLATE, 133 | $storeId 134 | )) { 135 | return 'invoice'; 136 | } 137 | 138 | if ($this->doesTemplateIdMatchConfig( 139 | $templateIdentifier, 140 | InvoiceCommentIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 141 | InvoiceCommentIdentity::XML_PATH_EMAIL_TEMPLATE, 142 | $storeId 143 | )) { 144 | return 'invoice_comment'; 145 | } 146 | 147 | return false; 148 | } 149 | 150 | private function getOrderEmail($templateIdentifier, $storeId) 151 | { 152 | if ($this->doesTemplateIdMatchConfig( 153 | $templateIdentifier, 154 | OrderIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 155 | OrderIdentity::XML_PATH_EMAIL_TEMPLATE, 156 | $storeId 157 | )) { 158 | return 'order'; 159 | } 160 | 161 | if ($this->doesTemplateIdMatchConfig( 162 | $templateIdentifier, 163 | OrderCommentIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 164 | OrderCommentIdentity::XML_PATH_EMAIL_TEMPLATE, 165 | $storeId 166 | )) { 167 | return 'order_comment'; 168 | } 169 | 170 | return false; 171 | } 172 | 173 | private function getCreditmemoEmail($templateIdentifier, $storeId) 174 | { 175 | if ($this->doesTemplateIdMatchConfig( 176 | $templateIdentifier, 177 | CreditmemoIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 178 | CreditmemoIdentity::XML_PATH_EMAIL_TEMPLATE, 179 | $storeId 180 | )) { 181 | return 'creditmemo'; 182 | } 183 | 184 | if ($this->doesTemplateIdMatchConfig( 185 | $templateIdentifier, 186 | CreditmemoCommentIdentity::XML_PATH_EMAIL_GUEST_TEMPLATE, 187 | CreditmemoCommentIdentity::XML_PATH_EMAIL_TEMPLATE, 188 | $storeId 189 | )) { 190 | return 'creditmemo_comment'; 191 | } 192 | 193 | return false; 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/Model/EmailType.php: -------------------------------------------------------------------------------- 1 | type = $type; 22 | $this->varCode = $varCode; 23 | } 24 | 25 | public function getType() 26 | { 27 | return $this->type; 28 | } 29 | 30 | public function getVarCode() 31 | { 32 | return $this->varCode; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/MailProcessor.php: -------------------------------------------------------------------------------- 1 | mimePartInterfaceFactory = $mimePartInterfaceFactory; 25 | } 26 | 27 | public function createMultipartMessage( 28 | array $existingParts, 29 | Api\AttachmentContainerInterface $attachmentContainer 30 | ) { 31 | 32 | foreach ($attachmentContainer->getAttachments() as $attachment) { 33 | $mimePart = $this->mimePartInterfaceFactory->create( 34 | [ 35 | 'content' => $attachment->getContent(), 36 | 'fileName' => $attachment->getFilename(true), 37 | 'type' => $attachment->getMimeType(), 38 | 'encoding' => $attachment->getEncoding(), 39 | 'disposition' => $attachment->getDisposition() 40 | ] 41 | ); 42 | 43 | $existingParts[] = $mimePart; 44 | } 45 | 46 | return $existingParts; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Model/NextEmailInfo.php: -------------------------------------------------------------------------------- 1 | templateVars = $templateVars; 20 | } 21 | 22 | public function getTemplateVars() 23 | { 24 | return $this->templateVars; 25 | } 26 | 27 | public function setTemplateIdentifier($templateIdentifier) 28 | { 29 | $this->templateIdentifier = $templateIdentifier; 30 | } 31 | 32 | public function getTemplateIdentifier() 33 | { 34 | return $this->templateIdentifier; 35 | } 36 | 37 | public function reset() 38 | { 39 | $this->templateIdentifier = null; 40 | $this->templateVars = null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Model/NoneRenderer.php: -------------------------------------------------------------------------------- 1 | pdfRenderer = $pdfRenderer; 20 | } 21 | 22 | public function getPdfAsString(array $salesObject) 23 | { 24 | return $this->pdfRenderer->getPdf($salesObject)->render(); 25 | } 26 | 27 | public function getFileName($input = '') 28 | { 29 | return sprintf('%s.pdf', $input); 30 | } 31 | 32 | public function canRender() 33 | { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Model/TermsAndConditionsAttacher.php: -------------------------------------------------------------------------------- 1 | termsCollection = $termsCollection; 26 | $this->contentAttacher = $contentAttacher; 27 | } 28 | 29 | public function attachForStore($storeId, ContainerInterface $attachmentContainer) 30 | { 31 | /** 32 | * @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $agreements 33 | */ 34 | $agreements = $this->termsCollection->create(); 35 | $agreements->addStoreFilter($storeId)->addFieldToFilter('is_active', "1"); 36 | 37 | foreach ($agreements as $agreement) { 38 | $this->attachAgreement($agreement, $attachmentContainer); 39 | } 40 | } 41 | 42 | public function attachAgreement(AgreementInterface $agreement, ContainerInterface $attachmentContainer) 43 | { 44 | if ($agreement->getIsHtml()) { 45 | $this->contentAttacher->addHtml( 46 | $this->buildHtmlAgreement($agreement), 47 | $agreement->getName() . '.html', 48 | $attachmentContainer 49 | ); 50 | } else { 51 | $this->contentAttacher->addText( 52 | $agreement->getContent(), 53 | $agreement->getName() . '.txt', 54 | $attachmentContainer 55 | ); 56 | } 57 | } 58 | 59 | private function buildHtmlAgreement(AgreementInterface $agreement) 60 | { 61 | return sprintf( 62 | ' 63 | 64 | 65 | %s 66 | 67 | %s 68 | ', 69 | $agreement->getName(), 70 | $agreement->getContent() 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Observer/AbstractObserver.php: -------------------------------------------------------------------------------- 1 | scopeConfig = $scopeConfig; 33 | $this->pdfRenderer = $pdfRenderer; 34 | $this->termsAttacher = $termsAttacher; 35 | $this->contentAttacher = $contentAttacher; 36 | } 37 | 38 | public function attachContent($content, $pdfFilename, $mimeType, ContainerInterface $attachmentContainer) 39 | { 40 | $this->contentAttacher->addGeneric($content, $pdfFilename, $mimeType, $attachmentContainer); 41 | } 42 | 43 | /** 44 | * @param string $pdfString 45 | * @param string $pdfFilename 46 | * @param ContainerInterface $attachmentContainer 47 | * 48 | * @deprecated see \Fooman\EmailAttachments\Model\ContentAttacher::addPdf() 49 | */ 50 | public function attachPdf($pdfString, $pdfFilename, ContainerInterface $attachmentContainer) 51 | { 52 | $this->contentAttacher->addPdf($pdfString, $pdfFilename, $attachmentContainer); 53 | } 54 | 55 | /** 56 | * @param string $text 57 | * @param string $filename 58 | * @param ContainerInterface $attachmentContainer 59 | * 60 | * @deprecated see \Fooman\EmailAttachments\Model\ContentAttacher::addText() 61 | */ 62 | public function attachTxt($text, $filename, ContainerInterface $attachmentContainer) 63 | { 64 | $this->contentAttacher->addText($text, $filename, $attachmentContainer); 65 | } 66 | 67 | /** 68 | * @param string $html 69 | * @param string $filename 70 | * @param ContainerInterface $attachmentContainer 71 | * 72 | * @deprecated see \Fooman\EmailAttachments\Model\ContentAttacher::addHtml() 73 | */ 74 | public function attachHtml($html, $filename, ContainerInterface $attachmentContainer) 75 | { 76 | $this->contentAttacher->addHtml($html, $filename, $attachmentContainer); 77 | } 78 | 79 | public function attachTermsAndConditions($storeId, ContainerInterface $attachmentContainer) 80 | { 81 | $this->termsAttacher->attachForStore($storeId, $attachmentContainer); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Observer/AbstractSendCreditmemoObserver.php: -------------------------------------------------------------------------------- 1 | getCreditmemo(); 23 | if ($this->pdfRenderer->canRender() 24 | && $this->scopeConfig->getValue( 25 | static::XML_PATH_ATTACH_PDF, 26 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 27 | $creditmemo->getStoreId() 28 | ) 29 | ) { 30 | $this->contentAttacher->addPdf( 31 | $this->pdfRenderer->getPdfAsString([$creditmemo]), 32 | $this->pdfRenderer->getFileName(__('Credit Memo') . $creditmemo->getIncrementId()), 33 | $observer->getAttachmentContainer() 34 | ); 35 | } 36 | 37 | if ($this->scopeConfig->getValue( 38 | static::XML_PATH_ATTACH_AGREEMENT, 39 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 40 | $creditmemo->getStoreId() 41 | ) 42 | ) { 43 | $this->attachTermsAndConditions($creditmemo->getStoreId(), $observer->getAttachmentContainer()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Observer/AbstractSendInvoiceObserver.php: -------------------------------------------------------------------------------- 1 | getInvoice(); 23 | if ($this->pdfRenderer->canRender() 24 | && $this->scopeConfig->getValue( 25 | static::XML_PATH_ATTACH_PDF, 26 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 27 | $invoice->getStoreId() 28 | ) 29 | ) { 30 | $this->contentAttacher->addPdf( 31 | $this->pdfRenderer->getPdfAsString([$invoice]), 32 | $this->pdfRenderer->getFileName(__('Invoice') . $invoice->getIncrementId()), 33 | $observer->getAttachmentContainer() 34 | ); 35 | } 36 | 37 | if ($this->scopeConfig->getValue( 38 | static::XML_PATH_ATTACH_AGREEMENT, 39 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 40 | $invoice->getStoreId() 41 | ) 42 | ) { 43 | $this->attachTermsAndConditions($invoice->getStoreId(), $observer->getAttachmentContainer()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Observer/AbstractSendInvoiceShipmentObserver.php: -------------------------------------------------------------------------------- 1 | getShipment(); 22 | 23 | if ($this->pdfRenderer->canRender() 24 | && $shipment->getOrder()->hasInvoices() 25 | && $this->scopeConfig->getValue( 26 | static::XML_PATH_ATTACH_PDF, 27 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 28 | $shipment->getStoreId() 29 | ) 30 | ) { 31 | foreach ($shipment->getOrder()->getInvoiceCollection() as $invoice) { 32 | $this->contentAttacher->addPdf( 33 | $this->pdfRenderer->getPdfAsString([$invoice]), 34 | $this->pdfRenderer->getFileName(__('Invoice') . $invoice->getIncrementId()), 35 | $observer->getAttachmentContainer() 36 | ); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Observer/AbstractSendOrderObserver.php: -------------------------------------------------------------------------------- 1 | getOrder(); 23 | if ($this->pdfRenderer->canRender() 24 | && $this->scopeConfig->getValue( 25 | static::XML_PATH_ATTACH_PDF, 26 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 27 | $order->getStoreId() 28 | ) 29 | ) { 30 | $this->contentAttacher->addPdf( 31 | $this->pdfRenderer->getPdfAsString([$order]), 32 | $this->pdfRenderer->getFileName(__('Order') . $order->getIncrementId()), 33 | $observer->getAttachmentContainer() 34 | ); 35 | } 36 | 37 | if ($this->scopeConfig->getValue( 38 | static::XML_PATH_ATTACH_AGREEMENT, 39 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 40 | $order->getStoreId() 41 | ) 42 | ) { 43 | $this->attachTermsAndConditions($order->getStoreId(), $observer->getAttachmentContainer()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Observer/AbstractSendShipmentObserver.php: -------------------------------------------------------------------------------- 1 | getShipment(); 24 | if ($this->pdfRenderer->canRender() 25 | && $this->scopeConfig->getValue( 26 | static::XML_PATH_ATTACH_PDF, 27 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 28 | $shipment->getStoreId() 29 | ) 30 | ) { 31 | $this->contentAttacher->addPdf( 32 | $this->pdfRenderer->getPdfAsString([$shipment]), 33 | $this->pdfRenderer->getFileName(__('Packing Slip') . $shipment->getIncrementId()), 34 | $observer->getAttachmentContainer() 35 | ); 36 | } 37 | 38 | if ($this->scopeConfig->getValue( 39 | static::XML_PATH_ATTACH_AGREEMENT, 40 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 41 | $shipment->getStoreId() 42 | ) 43 | ) { 44 | $this->attachTermsAndConditions($shipment->getStoreId(), $observer->getAttachmentContainer()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Observer/BeforeSendCreditmemoCommentObserver.php: -------------------------------------------------------------------------------- 1 | emailEventDispatcher = $emailEventDispatcher; 48 | $this->attachmentContainerFactory = $attachmentContainer; 49 | $this->mailProcessor = $mailProcessor; 50 | $this->isLaminasMode = version_compare($productMetadata->getVersion(), '2.4.8', '<'); 51 | } 52 | 53 | public function aroundCreate( 54 | \Magento\Framework\Mail\MimeMessageInterfaceFactory $subject, 55 | \Closure $proceed, 56 | array $data = [] 57 | ) { 58 | //Legacy Mode for Laminas Mail prior to Magento 2.4.8 59 | if ($this->isLaminasMode && isset($data['parts'])) { 60 | $attachmentContainer = $this->attachmentContainerFactory->create(); 61 | $this->emailEventDispatcher->dispatch($attachmentContainer); 62 | $data['parts'] = $this->attachIfNeeded($data['parts'], $attachmentContainer); 63 | } 64 | 65 | return $proceed($data); 66 | } 67 | 68 | public function attachIfNeeded($existingParts, AttachmentContainerInterface $attachmentContainer) 69 | { 70 | if (!$attachmentContainer->hasAttachments()) { 71 | return $existingParts; 72 | } 73 | return $this->mailProcessor->createMultipartMessage($existingParts, $attachmentContainer); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Plugin/Transport.php: -------------------------------------------------------------------------------- 1 | emailEventDispatcher = $emailEventDispatcher; 36 | $this->attachmentContainerFactory = $attachmentContainer; 37 | } 38 | 39 | public function beforeSendMessage( 40 | TransportInterface $subject 41 | ) { 42 | $attachmentContainer = $this->attachmentContainerFactory->create(); 43 | $this->emailEventDispatcher->dispatch($attachmentContainer); 44 | if (method_exists($subject->getMessage(), 'getSymfonyMessage')) { 45 | $this->handleSymfonyMail($attachmentContainer, $subject); 46 | } 47 | 48 | return null; 49 | } 50 | 51 | /** 52 | * @param $attachmentContainer 53 | * @param TransportInterface $subject 54 | * @return void 55 | */ 56 | private function handleSymfonyMail($attachmentContainer, TransportInterface $subject): void 57 | { 58 | $otherParts = []; 59 | if ($attachmentContainer->hasAttachments()) { 60 | foreach ($attachmentContainer->getAttachments() as $attachment) { 61 | $otherParts[] = new DataPart( 62 | $attachment->getContent(), 63 | $attachment->getFilename(true), 64 | $attachment->getMimeType(), 65 | $attachment->getEncoding() 66 | ); 67 | } 68 | $subject->getMessage()->getSymfonyMessage()->setBody( 69 | new MixedPart($subject->getMessage()->getSymfonyMessage()->getBody(), ...$otherParts) 70 | ); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Plugin/TransportBuilder.php: -------------------------------------------------------------------------------- 1 | nextEmail = $nextEmailInfo; 21 | } 22 | 23 | public function beforeSetTemplateIdentifier( 24 | \Magento\Framework\Mail\Template\TransportBuilder $subject, 25 | $templateIdentifier 26 | ) { 27 | $this->nextEmail->setTemplateIdentifier($templateIdentifier); 28 | } 29 | 30 | public function beforeSetTemplateVars( 31 | \Magento\Framework\Mail\Template\TransportBuilder $subject, 32 | $templateVars 33 | ) { 34 | $this->nextEmail->setTemplateVars($templateVars); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fooman/emailattachments-implementation-m2", 3 | "license": "OSL-3.0", 4 | "description": "Automatically attach pdf and terms and conditions documents to outgoing sales emails.", 5 | "type": "magento2-module", 6 | "version": "107.5.3", 7 | "autoload": { 8 | "psr-4": { 9 | "Fooman\\EmailAttachments\\": "" 10 | }, 11 | "files": [ 12 | "registration.php" 13 | ] 14 | }, 15 | "require": { 16 | "php": "~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0||~8.2.0||~8.3.0||~8.4.0", 17 | "magento/framework": "^102.0.5 || ^103.0.0", 18 | "magento/module-backend": "^101.0.0 || ^102.0.0", 19 | "magento/module-checkout-agreements": "^100.0.2", 20 | "magento/module-email": "^101.0.3", 21 | "magento/module-sales": "^102.0.0 || ^103.0.0" 22 | }, 23 | "minimum-stability": "dev", 24 | "prefer-stable": true, 25 | "suggest": { 26 | "fooman/printorderpdf-m2": "Allows attaching the order confirmation pdf to the order confirmation email", 27 | "fooman/pdfcustomiser-m2": "Allows to easily customise the sales pdfs while also reducing file sizes " 28 | } 29 | } -------------------------------------------------------------------------------- /src/etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 15 |
16 | 17 | 24 | Fooman\EmailAttachments\Block\Config\PrintOrderPdf 25 | Magento\Config\Model\Config\Source\Yesno 26 | 27 | When set to Yes, your order pdf document will be 28 | automatically attached to the order confirmation email. 29 | 30 | 37 | Magento\Config\Model\Config\Source\Yesno 38 | 39 | Stores > Terms and Conditions) 41 | will be automatically attached to the email.]]> 42 | 43 | 44 | 45 | 52 | Fooman\EmailAttachments\Block\Config\PrintOrderPdf 53 | Magento\Config\Model\Config\Source\Yesno 54 | 55 | When set to Yes, your order pdf document will be 56 | automatically attached to the order confirmation email. 57 | 58 | 65 | Magento\Config\Model\Config\Source\Yesno 66 | 67 | Stores > Terms and Conditions) 69 | will be automatically attached to the email.]]> 70 | 71 | 72 | 73 | 80 | 81 | Magento\Config\Model\Config\Source\Yesno 82 | When set to Yes, your invoice pdf document will be 83 | automatically attached to the invoice email. 84 | 85 | 92 | Magento\Config\Model\Config\Source\Yesno 93 | 94 | Stores > Terms and Conditions) 96 | will be automatically attached to the email.]]> 97 | 98 | 99 | 100 | 107 | 108 | Magento\Config\Model\Config\Source\Yesno 109 | When set to Yes, your invoice pdf document will be 110 | automatically attached to the invoice email. 111 | 112 | 119 | Magento\Config\Model\Config\Source\Yesno 120 | 121 | Stores > Terms and Conditions) 123 | will be automatically attached to the email.]]> 124 | 125 | 126 | 127 | 134 | 135 | Magento\Config\Model\Config\Source\Yesno 136 | When set to Yes, your packing slip pdf document will be 137 | automatically attached to the shipment email. 138 | 139 | 146 | 147 | Magento\Config\Model\Config\Source\Yesno 148 | When set to Yes, your invoice pdf document will be 149 | automatically attached to the shipment email. 150 | 151 | 158 | Magento\Config\Model\Config\Source\Yesno 159 | 160 | Stores > Terms and Conditions) 162 | will be automatically attached to the email.]]> 163 | 164 | 165 | 166 | 173 | 174 | Magento\Config\Model\Config\Source\Yesno 175 | When set to Yes, your packing slip pdf document will be 176 | automatically attached to the shipment email. 177 | 178 | 185 | 186 | Magento\Config\Model\Config\Source\Yesno 187 | When set to Yes, your invoice pdf document will be 188 | automatically attached to the shipment email. 189 | 190 | 197 | Magento\Config\Model\Config\Source\Yesno 198 | 199 | Stores > Terms and Conditions) 201 | will be automatically attached to the email.]]> 202 | 203 | 204 | 205 | 212 | Magento\Config\Model\Config\Source\Yesno 213 | 214 | When set to Yes, your packing slip pdf document will be 215 | automatically attached to the shipment comment email. 216 | 217 | 224 | Magento\Config\Model\Config\Source\Yesno 225 | 226 | Stores > Terms and Conditions) 228 | will be automatically attached to the email.]]> 229 | 230 | 231 | 232 | 239 | Magento\Config\Model\Config\Source\Yesno 240 | 241 | When set to Yes, your packing slip pdf document will be 242 | automatically attached to the shipment comment email. 243 | 244 | 251 | Magento\Config\Model\Config\Source\Yesno 252 | 253 | Stores > Terms and Conditions) 255 | will be automatically attached to the email.]]> 256 | 257 | 258 |
259 |
260 |
261 | -------------------------------------------------------------------------------- /src/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 15 | 16 | 17 | 0 18 | 19 | 20 | 0 21 | 22 | 23 | 0 24 | 25 | 26 | 0 27 | 28 | 29 | 0 30 | 31 | 32 | 0 33 | 34 | 35 | 0 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | Fooman\EmailAttachments\Model\NoneRenderer 34 | 35 | 36 | 37 | 38 | 39 | Magento\Sales\Model\Order\Pdf\Invoice 40 | 41 | 42 | 43 | 44 | fooman_emailattachments_invoice_pdf_renderer 45 | 46 | 47 | 48 | 49 | 50 | Magento\Sales\Model\Order\Pdf\Shipment 51 | 52 | 53 | 54 | 55 | fooman_emailattachments_shipment_pdf_renderer 56 | 57 | 58 | 59 | 60 | 61 | fooman_emailattachments_invoice_pdf_renderer 62 | 63 | 64 | 65 | 67 | 68 | Magento\Sales\Model\Order\Pdf\Creditmemo 69 | 70 | 71 | 72 | 73 | fooman_emailattachments_creditmemo_pdf_renderer 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 15 | 16 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 38 | 40 | 41 | 42 | 44 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/i18n/ar_SA.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","اربط فاتورة " 2 | "Attach Terms and Conditions","اربط شروط العقد" 3 | "Attach Packing Slip as PDF","اربط وصل التعبئة " 4 | "Attach Credit Memo as PDF","اربط عقد الادان" 5 | "Attach Order as PDF","اربط الطلب التجاري" 6 | -------------------------------------------------------------------------------- /src/i18n/ca_ES.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Adjuntar la factura en PDF" 2 | "Attach Terms and Conditions","Adjuntar Termes i Condicions" 3 | "Attach Packing Slip as PDF","Adjuntar fulla d'embalatge com PDF" 4 | "Attach Credit Memo as PDF","Adjuntar factura devolució com a PDF" 5 | "Attach Order as PDF","Adjuntar comanda en PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/cs_CZ.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Přiložit fakturu jako PDF" 2 | "Attach Terms and Conditions","Přiložit obchodní podmínky" 3 | "Attach Packing Slip as PDF","Přiložit dodací list jako PDF" 4 | "Attach Credit Memo as PDF","Přiložit dobropis jako PDF" 5 | "Attach Order as PDF","Přiložit objednávku jako PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/da_DK.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Vedhæft faktura som PDF" 2 | "Attach Terms and Conditions","Vedhæft handelsbetingelser" 3 | "Attach Packing Slip as PDF","Vedhæft følgeseddel som PDF" 4 | "Attach Credit Memo as PDF","Vedhæft kreditnota som PDF" 5 | "Attach Order as PDF","Vedhæft ordre som PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/de_DE.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Rechnung als PDF anhängen" 2 | "Attach Terms and Conditions","AGB als Emailanhang senden" 3 | "Attach Packing Slip as PDF","Packzettel als PDF anhängen" 4 | "Attach Credit Memo as PDF","Gutschrift als PDF anhängen" 5 | "Attach Order as PDF","Bestellung als PDF anhängen" 6 | -------------------------------------------------------------------------------- /src/i18n/en_US.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Attach Invoice as PDF" 2 | "Attach Terms and Conditions","Attach Terms and Conditions" 3 | "Attach Packing Slip as PDF","Attach Packing Slip as PDF" 4 | "Attach Credit Memo as PDF","Attach Credit Memo as PDF" 5 | "Attach Order as PDF","Attach Order as PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/es_ES.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Adjunta la Factura como PDF" 2 | "Attach Terms and Conditions","Adjunta los Terminos de venta y condiciones" 3 | "Attach Shipment as PDF","Adjunta los detalles del envio como PDF" 4 | "Attach Credit Memo as PDF","Adjunta el Memo de Credito como PDF" 5 | "Attach Order as PDF","Attach Order as PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/et_EE.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Kinnitage arve PDF" 2 | "Attach Terms and Conditions","Kinnitage tingimused" 3 | "Attach Packing Slip as PDF","Kinnitage saateleht PDF" 4 | "Attach Credit Memo as PDF","Kinnitage krediitarve PDF" 5 | "Attach Order as PDF","Kinnitage tellimus PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/fa_IR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as Pdf","ضمیمه کردن فاکتور به صورت Pdf" 2 | "Attach Terms and Conditions","ضمیمه کردن شرایط و ضوابط" 3 | "Attach Packing Slip as Pdf","ضمیمه کردن فهرست بسته بندی به صورت Pdf" 4 | "Attach Credit Memo as Pdf","ضمیمه کردن اعلامیه ی بستانکاری به صورت Pdf" 5 | "Attach Order as Pdf","ضمیمه کردن سفارش به صورت Pdf" 6 | -------------------------------------------------------------------------------- /src/i18n/fi_FI.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Liitä Lasku PDF-tiedostona" 2 | "Attach Terms and Conditions","Liitä Toimitusehdot" 3 | "Attach Packing Slip as PDF","Liitä Lähete PDF-tiedostona" 4 | "Attach Credit Memo as PDF","Liitä Hyvityslasku PDF-tiedostona" 5 | "Attach Order as PDF","Liitä Tilaus PDF-tiedostona" 6 | -------------------------------------------------------------------------------- /src/i18n/fr_FR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Joindre la Facture en PDF" 2 | "Attach Terms and Conditions","Joindre les CGV en PDF" 3 | "Attach Packing Slip as PDF","Joindre le Bon de livraison en PDF" 4 | "Attach Credit Memo as PDF","Joindre la Note d'Avoir en PDF" 5 | "Attach Order as PDF","Joindre la Commande en PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/gr_GR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Να συμπεριληφθεί το Τιμολόγιο σε μορφή PDF" 2 | "Attach Terms and Conditions","Να συμπεριληφθούν στο μύνημα οι Όροι Συναλλαγής" 3 | "Attach Packing Slip as PDF","Να συμπεριληφθεί η Φορτωτική σε μορφή PDF" 4 | "Attach Credit Memo as PDF","Να συμπεριληφθεί το Πιστωτικό Τιμολόγιο σε μορφή PDF" 5 | "Attach Order as PDF","Να συμπεριληφθεί η Παραγγελία σε μορφή PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/he_IL.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","צרף חשבונית בפורמט PDF" 2 | "Attach Terms and Conditions","צרף תנאי שימוש" 3 | "Attach Packing Slip as PDF","צרף תעודת משלוח בפורמט PDF" 4 | "Attach Credit Memo as PDF","צרף חשבונית זיכוי בפורמט PDF" 5 | "Attach Order as PDF","צרף הזמנה בפורמט PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/hr_HR.csv: -------------------------------------------------------------------------------- 1 | Attach Invoice as PDF,"Prikači račun kao PDF" 2 | Attach Terms and Conditions,"Dodaj uvjete poslovanja" 3 | Attach Packing Slip as PDF,"Dodaj otpremni list kao PDF" 4 | Attach Credit Memo as PDF,"Dodaj knjižni dopis kao PDV" 5 | Attach Order as PDF,"Dodaj narudžbenicu kao PDV" 6 | -------------------------------------------------------------------------------- /src/i18n/hu_HU.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Számla hozzáadása PDF-ként" 2 | "Attach Terms and Conditions","Felhasználási feltételek csatolása" 3 | "Attach Packing Slip as PDF","Szállító csatolása PDF-ként" 4 | "Attach Credit Memo as PDF","Tranzakció történet csatolása" 5 | "Attach Order as PDF","Rendelés csatolása PDF-ként" 6 | -------------------------------------------------------------------------------- /src/i18n/it_IT.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Allega fattura come PDF" 2 | "Attach Terms and Conditions","Allega Termini e condizioni di vendita" 3 | "Attach Packing Slip as PDF","Allega etichetta come PDF" 4 | "Attach Credit Memo as PDF","Allega Nota di credito come PDF" 5 | "Attach Order as PDF","Allega Ordine come PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/ja_JP.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","PDF領収証の添付" 2 | "Attach Terms and Conditions","支払い条件と詳細の添付" 3 | "Attach Packing Slip as PDF","発送伝票をPDFで添付" 4 | "Attach Credit Memo as PDF","クレジットメモ(訂正伝票)をPDFで添付" 5 | "Attach Order as PDF","注文確認書をPDFで添付" 6 | -------------------------------------------------------------------------------- /src/i18n/ko_KR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","송장 PDF로 첨부하기" 2 | "Attach Terms and Conditions","사용조건 첨부하기" 3 | "Attach Packing Slip as PDF","패킹리스트 PDF로 첨부하기" 4 | "Attach Credit Memo as PDF","환불메모 PDF로 첨부하기" 5 | "Attach Order as PDF","주문 PDF로 첨부하기" 6 | -------------------------------------------------------------------------------- /src/i18n/lt_LT.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Pridėti Sąskaitą kaip PDF" 2 | "Attach Terms and Conditions","Pridėti Sąlygas ir Terminus" 3 | "Attach Packing Slip as PDF","Pridėti Pristatymo Informaciją kaip PDF" 4 | "Attach Credit Memo as PDF","Pridėti Kredito Pastabas kaip PDF" 5 | "Attach Order as PDF","Pridėti Užsakymą kaip PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/lv_LV.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Piestiprināt rēķinu kā PDF failu" 2 | "Attach Terms and Conditions","Piestiprināt nosacījumu un noteikumu informāciju" 3 | "Attach Packing Slip as PDF","Piestiprināt iepakošanas ieliktni kā PDF failu" 4 | "Attach Credit Memo as PDF","Piestiprināt pirkuma piezīmes kā PDF failu" 5 | "Attach Order as PDF","Piestiprināt pasūtījumu kā PDF failu" 6 | -------------------------------------------------------------------------------- /src/i18n/nb_NO.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Legg ved faktura som PDF" 2 | "Attach Terms and Conditions","Legg ved salgs- og leveringsbetingelser som PDF" 3 | "Attach Packing Slip as PDF","Legg ved pakkseddel som PDF" 4 | "Attach Credit Memo as PDF","Legg ved kreditnota som PDF" 5 | "Attach Order as PDF","Legg ved ordre som PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/nl_NL.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Factuur toevoegen als PDF" 2 | "Attach Terms and Conditions","Algemene Voorwaarden toevoegen" 3 | "Attach Packing Slip as PDF","Pakbon toevoegen als PDF" 4 | "Attach Credit Memo as PDF","Creditnota toevoegen als PDF" 5 | "Attach Order as PDF","Orderbevestiging toevoegen als PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/no_NO.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Legg ved faktura som PDF" 2 | "Attach Terms and Conditions","Legg ved salgs- og leveringsbetingelser som PDF" 3 | "Attach Packing Slip as PDF","Legg ved pakkseddel som PDF" 4 | "Attach Credit Memo as PDF","Legg ved kreditnota som PDF" 5 | "Attach Order as PDF","Legg ved ordre som PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/pl_PL.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Dołącz fakturę jako PDF" 2 | "Attach Terms and Conditions","Dołącz warunki umowy i regulamin" 3 | "Attach Packing Slip as PDF","Dołącz specyfikację zawartości jako PDF" 4 | "Attach Credit Memo as PDF","Dołącz notę kredytową jako PDF" 5 | "Attach Order as PDF","Dołącz zamówienie jako PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/pt_BR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Anexar Fatura como PDF" 2 | "Attach Terms and Conditions","Anexar Termos e Condições" 3 | "Attach Packing Slip as PDF","Anexar Envio como PDF" 4 | "Attach Credit Memo as PDF","Anexar Memorando de Crédito como PDF" 5 | "Attach Order as PDF","Anexar Pedido como PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/ro_RO.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Ataşaţi factura în format PDF" 2 | "Attach Terms and Conditions","Ataşati Termeni şi Condiţii" 3 | "Attach Packing Slip as PDF","Ataşaţi Avizul de Livrare în format PDF" 4 | "Attach Credit Memo as PDF","Ataşaţi Avizul de Returnare în format PDF" 5 | "Attach Order as PDF","Ataşaţi Formularul de Comanda în format PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/ru_RU.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Счёт как DPF приложение" 2 | "Attach Terms and Conditions","Условия как PDF приложение" 3 | "Attach Packing Slip as PDF","Путевой лист как PDF приложение" 4 | "Attach Credit Memo as PDF","Кредитовый счёт как PDF приложение" 5 | "Attach Order as PDF","Подтверждение заказа как DPF приложение" 6 | -------------------------------------------------------------------------------- /src/i18n/sk_SK.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as Pdf","Priložiť faktúru ako Pdf" 2 | "Attach Terms and Conditions","Priložiť obchodné podmienky" 3 | "Attach Packing Slip as Pdf","Priložiť dodací list ako Pdf" 4 | "Attach Credit Memo as Pdf","Priložiť dobropis ako Pdf" 5 | "Attach Order as Pdf","Priložiť objednávku ako Pdf" 6 | -------------------------------------------------------------------------------- /src/i18n/sl_SI.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Pripni račun v PDF obliki" 2 | "Attach Terms and Conditions","Pripni splošne pogoje poslovanja" 3 | "Attach Packing Slip as PDF","Pripni odpremni list v PDF obliki" 4 | "Attach Credit Memo as PDF","Pripni dobropis v PDF obliki" 5 | "Attach Order as PDF","Pripni naročilo v PDF obliki" 6 | -------------------------------------------------------------------------------- /src/i18n/sv_SE.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Bifoga faktura som PDF" 2 | "Attach Terms and Conditions","Bifoga allmänna villkor" 3 | "Attach Packing Slip as PDF","Bifoga plocklista som PDF" 4 | "Attach Credit Memo as PDF","Bifoga kreditfaktura som PDF" 5 | "Attach Order as PDF","Bifoga order som PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/th_TH.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Attach Invoice as PDF" 2 | "Attach Terms and Conditions","Attach Terms and Conditions" 3 | "Attach Packing Slip as PDF","Attach Packing Slip as PDF" 4 | "Attach Credit Memo as PDF","Attach Credit Memo as PDF" 5 | "Attach Order as PDF","Attach Order as PDF" 6 | -------------------------------------------------------------------------------- /src/i18n/tr_TR.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","Faturayı PDF Olarak Ekle" 2 | "Attach Terms and Conditions","Sözleşmeleri Ekle" 3 | "Attach Packing Slip as PDF","Toplama Listelerini PDF Olarak Ekle" 4 | "Attach Credit Memo as PDF","Alacakları PDF Olarak Ekle" 5 | "Attach Order as PDF","Siparişleri PDF Olarak Ekle" 6 | -------------------------------------------------------------------------------- /src/i18n/zh_CN.csv: -------------------------------------------------------------------------------- 1 | "Attach Invoice as PDF","附上發票 (PDF格式)" 2 | "Attach Terms and Conditions","附上條款及條件" 3 | "Attach Packing Slip as PDF","附上送貨單 (PDF格式)" 4 | "Attach Credit Memo as PDF","附上信用備忘錄 (PDF格式)" 5 | "Attach Order as PDF","附上訂購 (PDF格式)" 6 | -------------------------------------------------------------------------------- /src/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/acceptance/Mftf/Page/AdminEmailAttachmentsConfigurationPage.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 |
6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/acceptance/Mftf/Section/AdminFoomanEmailAttachmentsSettingsSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 |
5 | 6 | 7 | 8 |
9 |
10 | -------------------------------------------------------------------------------- /tests/acceptance/Mftf/Test/AdminCheckInvoiceEmailSendTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | <description value="Check that invoice email attachment works correctly"/> 10 | 11 | <severity value="CRITICAL"/> 12 | <group value="Fooman_All"/> 13 | <group value="Fooman_EmailAttachments"/> 14 | </annotations> 15 | <before> 16 | <createData entity="_defaultCategory" stepKey="createCategory"/> 17 | <createData entity="_defaultProduct" stepKey="createSimpleProduct"> 18 | <requiredEntity createDataKey="createCategory"/> 19 | </createData> 20 | <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> 21 | <actionGroup ref="AdminConfigureFoomanEmailAttachmentsActionGroup" stepKey="resetSettings" /> 22 | </before> 23 | <!--Go to product page--> 24 | <amOnPage url="$$createSimpleProduct.custom_attributes[url_key]$$.html" stepKey="navigateToSimpleProductPage2"/> 25 | <waitForPageLoad stepKey="waitForCatalogPageLoad2"/> 26 | 27 | <!--Add Product to Shopping Cart--> 28 | <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage2"> 29 | <argument name="productName" value="$$createSimpleProduct.name$$"/> 30 | </actionGroup> 31 | 32 | <!--Go to Checkout--> 33 | <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart2"/> 34 | <actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="guestCheckoutFillingShippingSection2"> 35 | <argument name="customerVar" value="CustomerEntityOne" /> 36 | <argument name="customerAddressVar" value="CustomerAddressSimple" /> 37 | </actionGroup> 38 | <!-- Checkout select Check/Money Order payment --> 39 | <actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment2"/> 40 | 41 | <!--Click Place Order button--> 42 | <click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder2"/> 43 | 44 | <!--Go to product page--> 45 | <amOnPage url="$$createSimpleProduct.custom_attributes[url_key]$$.html" stepKey="navigateToSimpleProductPage3"/> 46 | <waitForPageLoad stepKey="waitForCatalogPageLoad3"/> 47 | 48 | <!--Add Product to Shopping Cart--> 49 | <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage3"> 50 | <argument name="productName" value="$$createSimpleProduct.name$$"/> 51 | </actionGroup> 52 | 53 | <!--Go to Checkout--> 54 | <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart3"/> 55 | <actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="guestCheckoutFillingShippingSection3"> 56 | <argument name="customerVar" value="CustomerEntityOne" /> 57 | <argument name="customerAddressVar" value="CustomerAddressSimple" /> 58 | </actionGroup> 59 | <!-- Checkout select Check/Money Order payment --> 60 | <actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment3"/> 61 | 62 | <!--Click Place Order button--> 63 | <click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder3"/> 64 | 65 | <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber}}" stepKey="grabOrderNumber2"/> 66 | 67 | <!--Create invoice in admin--> 68 | <amOnPage url="{{AdminOrdersPage.url}}" stepKey="onOrdersPage"/> 69 | <waitForPageLoad stepKey="waitForIndexPageLoad"/> 70 | <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilter"/> 71 | <fillField selector="{{AdminOrdersGridSection.search}}" userInput="{$grabOrderNumber2}" stepKey="searchOrderNum"/> 72 | <click selector="{{AdminOrdersGridSection.submitSearch}}" stepKey="submitSearch"/> 73 | <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask4"/> 74 | 75 | <click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/> 76 | <click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoice"/> 77 | <click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/> 78 | <waitForPageLoad stepKey="waitForInvoicePageLoad"/> 79 | <see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="The invoice has been created." stepKey="seeSuccessMessage"/> 80 | </test> 81 | </tests> 82 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendCreditmemoCommentObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendCreditmemoCommentObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 21 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): void 25 | { 26 | $creditmemo = $this->sendEmail(); 27 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 28 | $pdf = $this->objectManager 29 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\CreditmemoAdapter::class) 30 | ->getPdfAsString([$creditmemo]); 31 | $this->comparePdfAsStringWithReceivedPdf( 32 | $pdf, 33 | sprintf('CREDITMEMO_%s.pdf', $creditmemo->getIncrementId()) 34 | ); 35 | } else { 36 | $pdf = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 37 | ->create(\Magento\Sales\Model\Order\Pdf\Creditmemo::class)->getPdf([$creditmemo]); 38 | $this->compareWithReceivedPdf($pdf); 39 | } 40 | } 41 | 42 | /** 43 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 44 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 45 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachagreement 1 46 | */ 47 | public function testWithHtmlTermsAttachment(): void 48 | { 49 | $this->sendEmail(); 50 | $this->checkReceivedHtmlTermsAttachment(); 51 | } 52 | 53 | /** 54 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 55 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 56 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachagreement 1 57 | */ 58 | public function testWithTextTermsAttachment(): void 59 | { 60 | $this->sendEmail(); 61 | $this->checkReceivedTxtTermsAttachment(); 62 | } 63 | 64 | /** 65 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 66 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachpdf 0 67 | */ 68 | public function testWithoutAttachment(): void 69 | { 70 | $this->sendEmail(); 71 | 72 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 73 | self::assertFalse($pdfAttachment); 74 | } 75 | 76 | /** 77 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 78 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 79 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachagreement 1 80 | * @magentoConfigFixture current_store sales_email/creditmemo_comment/attachpdf 1 81 | */ 82 | public function testMultipleAttachments(): void 83 | { 84 | $this->testWithAttachment(); 85 | $this->checkReceivedHtmlTermsAttachment(1, 1); 86 | } 87 | 88 | protected function getCreditmemo() 89 | { 90 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 91 | \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection::class 92 | )->setPageSize(1); 93 | $creditmemo = $collection->getFirstItem(); 94 | foreach ($creditmemo->getAllItems() as $item) { 95 | if (!$item->getSku()) { 96 | $item->setSku('Test_sku'); 97 | } 98 | if (!$item->getName()) { 99 | $item->setName('Test Name'); 100 | } 101 | } 102 | return $creditmemo; 103 | } 104 | 105 | /** 106 | * @return \Magento\Sales\Api\Data\CreditmemoInterface 107 | */ 108 | protected function sendEmail(): \Magento\Sales\Api\Data\CreditmemoInterface 109 | { 110 | $creditmemo = $this->getCreditmemo(); 111 | $creditmemoSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 112 | ->create(\Magento\Sales\Model\Order\Email\Sender\CreditmemoCommentSender::class); 113 | 114 | $creditmemoSender->send($creditmemo); 115 | return $creditmemo; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendCreditmemoObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendCreditmemoObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 21 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): \Magento\Sales\Api\Data\CreditmemoInterface 25 | { 26 | $creditmemo = $this->sendEmail(); 27 | $this->comparePdfs($creditmemo); 28 | return $creditmemo; 29 | } 30 | 31 | private function comparePdfs($creditmemo, $number = 1): void 32 | { 33 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 34 | $pdf = $this->objectManager 35 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\CreditmemoAdapter::class) 36 | ->getPdfAsString([$creditmemo]); 37 | $this->comparePdfAsStringWithReceivedPdf( 38 | $pdf, 39 | sprintf('CREDITMEMO_%s.pdf', $creditmemo->getIncrementId()), 40 | $number 41 | ); 42 | } else { 43 | $pdf = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 44 | ->create(\Magento\Sales\Model\Order\Pdf\Creditmemo::class)->getPdf([$creditmemo]); 45 | $this->compareWithReceivedPdf($pdf, $number); 46 | } 47 | } 48 | 49 | /** 50 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 51 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 52 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 53 | */ 54 | public function testWithHtmlTermsAttachment(): void 55 | { 56 | $this->sendEmail(); 57 | $this->checkReceivedHtmlTermsAttachment(); 58 | } 59 | 60 | /** 61 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 62 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 63 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 64 | */ 65 | public function testWithTextTermsAttachment(): void 66 | { 67 | $this->sendEmail(); 68 | $this->checkReceivedTxtTermsAttachment(); 69 | } 70 | 71 | /** 72 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 73 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 0 74 | */ 75 | public function testWithoutAttachment(): void 76 | { 77 | $this->sendEmail(); 78 | 79 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 80 | self::assertFalse($pdfAttachment); 81 | } 82 | 83 | /** 84 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 85 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 86 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 87 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 1 88 | */ 89 | public function testMultipleAttachments(): void 90 | { 91 | $this->testWithAttachment(); 92 | $this->checkReceivedHtmlTermsAttachment(1, 1); 93 | } 94 | 95 | /** 96 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 97 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 98 | * @magentoAppIsolation enabled 99 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 100 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 1 101 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_method copy 102 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_to copyto@example.com 103 | */ 104 | public function testWithCopyToRecipient(): void 105 | { 106 | $creditmemo = $this->testWithAttachment(); 107 | $this->checkReceivedHtmlTermsAttachment(1, 1); 108 | $this->checkReceivedHtmlTermsAttachment(2, 1); 109 | $this->comparePdfs($creditmemo, 1); 110 | } 111 | 112 | /** 113 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 114 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 115 | * @magentoAppIsolation enabled 116 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 117 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 1 118 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_method copy 119 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_to copyto@example.com 120 | */ 121 | public function testWithMultipleCopyToRecipients(): void 122 | { 123 | $creditmemo = $this->testWithAttachment(); 124 | $this->checkReceivedHtmlTermsAttachment(1, 1); 125 | $this->checkReceivedHtmlTermsAttachment(2, 1); 126 | //$this->checkReceivedHtmlTermsAttachment(3, 1); 127 | $this->comparePdfs($creditmemo, 1); 128 | $mail = $this->getLastEmail(); 129 | 130 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 131 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 132 | self::assertCount(2, $allPdfAttachments); 133 | } else { 134 | self::assertCount(1, $allPdfAttachments); 135 | } 136 | } 137 | 138 | /** 139 | * @magentoDataFixture Magento/Sales/_files/creditmemo_with_list.php 140 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 141 | * @magentoAppIsolation enabled 142 | * @magentoConfigFixture current_store sales_email/creditmemo/attachagreement 1 143 | * @magentoConfigFixture current_store sales_email/creditmemo/attachpdf 1 144 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_method bcc 145 | * @magentoConfigFixture current_store sales_email/creditmemo/copy_to copyto@example.com 146 | */ 147 | public function testWithBccRecipient(): void 148 | { 149 | $this->testWithAttachment(); 150 | $this->checkReceivedHtmlTermsAttachment(1, 1); 151 | $mail = $this->getLastEmail(); 152 | self::assertEquals('copyto@example.com', $mail['Bcc'][0]['Address']); 153 | 154 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 155 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 156 | self::assertCount(2, $allPdfAttachments); 157 | } else { 158 | self::assertCount(1, $allPdfAttachments); 159 | } 160 | } 161 | 162 | protected function getCreditmemo() 163 | { 164 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 165 | \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection::class 166 | )->setPageSize(1); 167 | $creditmemo = $collection->getFirstItem(); 168 | foreach ($creditmemo->getAllItems() as $item) { 169 | if (!$item->getSku()) { 170 | $item->setSku('Test_sku'); 171 | } 172 | if (!$item->getName()) { 173 | $item->setName('Test Name'); 174 | } 175 | } 176 | return $creditmemo; 177 | } 178 | 179 | /** 180 | * @return \Magento\Sales\Api\Data\CreditmemoInterface 181 | */ 182 | protected function sendEmail(): \Magento\Sales\Api\Data\CreditmemoInterface 183 | { 184 | $creditmemo = $this->getCreditmemo(); 185 | $creditmemoSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 186 | ->create(\Magento\Sales\Model\Order\Email\Sender\CreditmemoSender::class); 187 | 188 | $creditmemoSender->send($creditmemo); 189 | return $creditmemo; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendInvoiceCommentObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendInvoiceCommentObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/invoice.php 21 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): void 25 | { 26 | $invoice = $this->sendEmail(); 27 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 28 | $pdf = $this->objectManager 29 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\InvoiceAdapter::class) 30 | ->getPdfAsString([$invoice]); 31 | $this->comparePdfAsStringWithReceivedPdf($pdf, sprintf('TAXINVOICE_%s.pdf', $invoice->getIncrementId())); 32 | } else { 33 | $pdf = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 34 | ->create(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf([$invoice]); 35 | $this->compareWithReceivedPdf($pdf); 36 | } 37 | } 38 | 39 | /** 40 | * @magentoDataFixture Magento/Sales/_files/invoice.php 41 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 42 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachagreement 1 43 | */ 44 | public function testWithHtmlTermsAttachment(): void 45 | { 46 | $this->sendEmail(); 47 | $this->checkReceivedHtmlTermsAttachment(); 48 | } 49 | 50 | /** 51 | * @magentoDataFixture Magento/Sales/_files/invoice.php 52 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 53 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachagreement 1 54 | */ 55 | public function testWithTextTermsAttachment(): void 56 | { 57 | $this->sendEmail(); 58 | $this->checkReceivedTxtTermsAttachment(); 59 | } 60 | 61 | /** 62 | * @magentoDataFixture Magento/Sales/_files/invoice.php 63 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachpdf 0 64 | */ 65 | public function testWithoutAttachment(): void 66 | { 67 | $this->sendEmail(); 68 | 69 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 70 | self::assertFalse($pdfAttachment); 71 | } 72 | 73 | /** 74 | * @magentoDataFixture Magento/Sales/_files/invoice.php 75 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 76 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachagreement 1 77 | * @magentoConfigFixture current_store sales_email/invoice_comment/attachpdf 1 78 | */ 79 | public function testMultipleAttachments(): void 80 | { 81 | $this->testWithAttachment(); 82 | $this->checkReceivedHtmlTermsAttachment(1, 1); 83 | } 84 | 85 | protected function getInvoice() 86 | { 87 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 88 | \Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class 89 | )->setPageSize(1); 90 | $invoice = $collection->getFirstItem(); 91 | foreach ($invoice->getAllItems() as $item) { 92 | if (!$item->getSku()) { 93 | $item->setSku('Test_sku'); 94 | } 95 | } 96 | return $invoice; 97 | } 98 | 99 | /** 100 | * @return \Magento\Sales\Api\Data\InvoiceInterface 101 | */ 102 | protected function sendEmail(): \Magento\Sales\Api\Data\InvoiceInterface 103 | { 104 | $invoice = $this->getInvoice(); 105 | $invoiceSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 106 | ->create(\Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender::class); 107 | 108 | $invoiceSender->send($invoice); 109 | return $invoice; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendInvoiceObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendInvoiceObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/invoice.php 21 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): \Magento\Sales\Api\Data\InvoiceInterface 25 | { 26 | $invoice = $this->sendEmail(); 27 | $this->comparePdfs($invoice); 28 | return $invoice; 29 | } 30 | 31 | private function comparePdfs($invoice, $number = 1): void 32 | { 33 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 34 | $pdf = $this->objectManager 35 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\InvoiceAdapter::class) 36 | ->getPdfAsString([$invoice]); 37 | $this->comparePdfAsStringWithReceivedPdf( 38 | $pdf, 39 | sprintf('TAXINVOICE_%s.pdf', $invoice->getIncrementId()), 40 | $number 41 | ); 42 | } else { 43 | $pdf = $this->objectManager->create(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf([$invoice]); 44 | $this->compareWithReceivedPdf($pdf, $number); 45 | } 46 | } 47 | 48 | /** 49 | * @magentoDataFixture Magento/Sales/_files/invoice.php 50 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 51 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 52 | */ 53 | public function testWithHtmlTermsAttachment(): void 54 | { 55 | $this->sendEmail(); 56 | $this->checkReceivedHtmlTermsAttachment(); 57 | } 58 | 59 | /** 60 | * @magentoDataFixture Magento/Sales/_files/invoice.php 61 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 62 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 63 | */ 64 | public function testWithTextTermsAttachment(): void 65 | { 66 | $this->sendEmail(); 67 | $this->checkReceivedTxtTermsAttachment(); 68 | } 69 | 70 | /** 71 | * @magentoDataFixture Magento/Sales/_files/invoice.php 72 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 0 73 | */ 74 | public function testWithoutAttachment(): void 75 | { 76 | $this->sendEmail(); 77 | 78 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 79 | self::assertFalse($pdfAttachment); 80 | } 81 | 82 | /** 83 | * @magentoDataFixture Magento/Sales/_files/invoice.php 84 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 85 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 86 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 1 87 | */ 88 | public function testMultipleAttachments(): void 89 | { 90 | $this->testWithAttachment(); 91 | $this->checkReceivedHtmlTermsAttachment(1, 1); 92 | } 93 | 94 | /** 95 | * @magentoDataFixture Magento/Sales/_files/invoice.php 96 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 97 | * @magentoAppIsolation enabled 98 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 99 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 1 100 | * @magentoConfigFixture current_store sales_email/invoice/copy_method copy 101 | * @magentoConfigFixture current_store sales_email/invoice/copy_to copyto@example.com 102 | */ 103 | public function testWithCopyToRecipient(): void 104 | { 105 | $invoice = $this->testWithAttachment(); 106 | $this->checkReceivedHtmlTermsAttachment(1, 1); 107 | $this->checkReceivedHtmlTermsAttachment(2, 1); 108 | $this->comparePdfs($invoice, 1); 109 | } 110 | 111 | /** 112 | * @magentoDataFixture Magento/Sales/_files/invoice.php 113 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 114 | * @magentoAppIsolation enabled 115 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 116 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 1 117 | * @magentoConfigFixture current_store sales_email/invoice/copy_method copy 118 | * @magentoConfigFixture current_store sales_email/invoice/copy_to copyto@example.com 119 | */ 120 | public function testWithMultipleCopyToRecipients(): void 121 | { 122 | $invoice = $this->testWithAttachment(); 123 | $this->checkReceivedHtmlTermsAttachment(1, 1); 124 | $this->checkReceivedHtmlTermsAttachment(2, 1); 125 | //$this->checkReceivedHtmlTermsAttachment(3, 1); 126 | $this->comparePdfs($invoice, 1); 127 | $mail = $this->getLastEmail(); 128 | 129 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 130 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 131 | self::assertCount(2, $allPdfAttachments); 132 | } else { 133 | self::assertCount(1, $allPdfAttachments); 134 | } 135 | } 136 | 137 | /** 138 | * @magentoDataFixture Magento/Sales/_files/invoice.php 139 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 140 | * @magentoAppIsolation enabled 141 | * @magentoConfigFixture current_store sales_email/invoice/attachagreement 1 142 | * @magentoConfigFixture current_store sales_email/invoice/attachpdf 1 143 | * @magentoConfigFixture current_store sales_email/invoice/copy_method bcc 144 | * @magentoConfigFixture current_store sales_email/invoice/copy_to copyto@example.com 145 | */ 146 | public function testWithBccRecipient(): void 147 | { 148 | $this->testWithAttachment(); 149 | $this->checkReceivedHtmlTermsAttachment(1, 1); 150 | $mail = $this->getLastEmail(); 151 | self::assertEquals('copyto@example.com', $mail['Bcc'][0]['Address']); 152 | 153 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 154 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 155 | self::assertCount(2, $allPdfAttachments); 156 | } else { 157 | self::assertCount(1, $allPdfAttachments); 158 | } 159 | } 160 | 161 | protected function getInvoice(): \Magento\Sales\Api\Data\InvoiceInterface 162 | { 163 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 164 | \Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class 165 | )->setPageSize(1); 166 | $invoice = $collection->getFirstItem(); 167 | foreach ($invoice->getAllItems() as $item) { 168 | if (!$item->getSku()) { 169 | $item->setSku('Test_sku'); 170 | } 171 | } 172 | return $invoice; 173 | } 174 | 175 | /** 176 | * @return \Magento\Sales\Api\Data\InvoiceInterface 177 | */ 178 | protected function sendEmail(): \Magento\Sales\Api\Data\InvoiceInterface 179 | { 180 | $invoice = $this->getInvoice(); 181 | $invoiceSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 182 | ->create(\Magento\Sales\Model\Order\Email\Sender\InvoiceSender::class); 183 | 184 | $invoiceSender->send($invoice); 185 | return $invoice; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendOrderCommentObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendOrderCommentObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/order.php 21 | * @magentoConfigFixture current_store sales_email/order_comment/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): void 25 | { 26 | $order = $this->sendEmail(); 27 | 28 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 29 | $pdf = $this->objectManager 30 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\OrderAdapter::class) 31 | ->getPdfAsString([$order]); 32 | $this->comparePdfAsStringWithReceivedPdf( 33 | $pdf, 34 | sprintf('ORDERCONFIRMATION_%s.pdf', $order->getIncrementId()) 35 | ); 36 | } else { 37 | self::assertTrue(true, 'Make at least 1 assertion'); 38 | if ($this->moduleManager->isEnabled('Fooman_PrintOrderPdf')) { 39 | $pdf = $this->objectManager->create(\Fooman\PrintOrderPdf\Model\Pdf\Order::class)->getPdf([$order]); 40 | $this->compareWithReceivedPdf($pdf); 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * @magentoDataFixture Magento/Sales/_files/order.php 47 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 48 | * @magentoConfigFixture current_store sales_email/order_comment/attachagreement 1 49 | */ 50 | public function testWithHtmlTermsAttachment(): void 51 | { 52 | $this->sendEmail(); 53 | $this->checkReceivedHtmlTermsAttachment(); 54 | } 55 | 56 | /** 57 | * @magentoDataFixture Magento/Sales/_files/order.php 58 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 59 | * @magentoConfigFixture current_store sales_email/order_comment/attachagreement 1 60 | */ 61 | public function testWithTextTermsAttachment(): void 62 | { 63 | $this->sendEmail(); 64 | $this->checkReceivedTxtTermsAttachment(); 65 | } 66 | 67 | /** 68 | * @magentoDataFixture Magento/Sales/_files/order.php 69 | * @magentoConfigFixture current_store sales_email/order_comment/attachpdf 0 70 | */ 71 | public function testWithoutAttachment(): void 72 | { 73 | $this->sendEmail(); 74 | 75 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 76 | self::assertFalse($pdfAttachment); 77 | } 78 | 79 | /** 80 | * @magentoDataFixture Magento/Sales/_files/order.php 81 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 82 | * @magentoAppIsolation enabled 83 | * @magentoConfigFixture current_store sales_email/order_comment/attachagreement 1 84 | * @magentoConfigFixture current_store sales_email/order_comment/attachpdf 1 85 | */ 86 | public function testMultipleAttachments(): void 87 | { 88 | $this->testWithAttachment(); 89 | $this->checkReceivedHtmlTermsAttachment(1, 1); 90 | } 91 | 92 | protected function getOrder(): \Magento\Sales\Api\Data\OrderInterface 93 | { 94 | $collection = $this->objectManager->create( 95 | \Magento\Sales\Model\ResourceModel\Order\Collection::class 96 | )->setPageSize(1); 97 | $order = $collection->getFirstItem(); 98 | foreach ($order->getAllItems() as $orderItem) { 99 | if (!$orderItem->getSku()) { 100 | $orderItem->setSku('Test_sku'); 101 | } 102 | } 103 | return $order; 104 | } 105 | 106 | /** 107 | * @return \Magento\Sales\Api\Data\OrderInterface 108 | */ 109 | protected function sendEmail(): \Magento\Sales\Api\Data\OrderInterface 110 | { 111 | $order = $this->getOrder(); 112 | $orderSender = $this->objectManager 113 | ->create(\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender::class); 114 | 115 | $orderSender->send($order); 116 | return $order; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendOrderObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendOrderObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/order.php 21 | * @magentoConfigFixture current_store sales_email/order/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): void 25 | { 26 | $order = $this->sendEmail(); 27 | 28 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 29 | $pdf = $this->objectManager 30 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\OrderAdapter::class) 31 | ->getPdfAsString([$order]); 32 | $this->comparePdfAsStringWithReceivedPdf( 33 | $pdf, 34 | sprintf('ORDERCONFIRMATION_%s.pdf', $order->getIncrementId()) 35 | ); 36 | } else { 37 | self::assertTrue(true, 'Make at least 1 assertion'); 38 | if ($this->moduleManager->isEnabled('Fooman_PrintOrderPdf')) { 39 | $pdf = $this->objectManager->create(\Fooman\PrintOrderPdf\Model\Pdf\Order::class)->getPdf([$order]); 40 | $this->compareWithReceivedPdf($pdf); 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * @magentoDataFixture Magento/Sales/_files/order.php 47 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 48 | * @magentoConfigFixture current_store sales_email/order/attachagreement 1 49 | */ 50 | public function testWithHtmlTermsAttachment(): void 51 | { 52 | $this->sendEmail(); 53 | $this->checkReceivedHtmlTermsAttachment(); 54 | } 55 | 56 | /** 57 | * @magentoDataFixture Magento/Sales/_files/order.php 58 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 59 | * @magentoConfigFixture current_store sales_email/order/attachagreement 1 60 | */ 61 | public function testWithTextTermsAttachment(): void 62 | { 63 | $this->sendEmail(); 64 | $this->checkReceivedTxtTermsAttachment(); 65 | } 66 | 67 | /** 68 | * @magentoDataFixture Magento/Sales/_files/order.php 69 | * @magentoConfigFixture current_store sales_email/order/attachpdf 0 70 | */ 71 | public function testWithoutAttachment(): void 72 | { 73 | $this->sendEmail(); 74 | 75 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 76 | self::assertFalse($pdfAttachment); 77 | } 78 | 79 | /** 80 | * @magentoDataFixture Magento/Sales/_files/order.php 81 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 82 | * @magentoAppIsolation enabled 83 | * @magentoConfigFixture current_store sales_email/order/attachagreement 1 84 | * @magentoConfigFixture current_store sales_email/order/attachpdf 1 85 | */ 86 | public function testMultipleAttachments(): void 87 | { 88 | $this->testWithAttachment(); 89 | $this->checkReceivedHtmlTermsAttachment(1, 1); 90 | } 91 | 92 | protected function getOrder(): \Magento\Sales\Api\Data\OrderInterface 93 | { 94 | $collection = $this->objectManager->create( 95 | \Magento\Sales\Model\ResourceModel\Order\Collection::class 96 | )->setPageSize(1); 97 | $order = $collection->getFirstItem(); 98 | foreach ($order->getAllItems() as $orderItem) { 99 | if (!$orderItem->getSku()) { 100 | $orderItem->setSku('Test_sku'); 101 | } 102 | } 103 | return $order; 104 | } 105 | 106 | /** 107 | * @return \Magento\Sales\Api\Data\OrderInterface 108 | */ 109 | protected function sendEmail(): \Magento\Sales\Api\Data\OrderInterface 110 | { 111 | $order = $this->getOrder(); 112 | $orderSender = $this->objectManager 113 | ->create(\Magento\Sales\Model\Order\Email\Sender\OrderSender::class); 114 | 115 | $orderSender->send($order); 116 | return $order; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendShipmentCommentObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendShipmentCommentObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/shipment.php 21 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): void 25 | { 26 | $shipment = $this->sendEmail(); 27 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 28 | $pdf = $this->objectManager 29 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\ShipmentAdapter::class) 30 | ->getPdfAsString([$shipment]); 31 | $this->comparePdfAsStringWithReceivedPdf( 32 | $pdf, 33 | sprintf('PACKINGSLIP_%s.pdf', $shipment->getIncrementId()) 34 | ); 35 | } else { 36 | $pdf = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 37 | ->create(\Magento\Sales\Model\Order\Pdf\Shipment::class)->getPdf([$shipment]); 38 | $this->compareWithReceivedPdf($pdf); 39 | } 40 | } 41 | 42 | /** 43 | * @magentoDataFixture Magento/Sales/_files/shipment.php 44 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 45 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachagreement 1 46 | */ 47 | public function testWithHtmlTermsAttachment(): void 48 | { 49 | $this->sendEmail(); 50 | $this->checkReceivedHtmlTermsAttachment(); 51 | } 52 | 53 | /** 54 | * @magentoDataFixture Magento/Sales/_files/shipment.php 55 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 56 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachagreement 1 57 | */ 58 | public function testWithTextTermsAttachment(): void 59 | { 60 | $this->sendEmail(); 61 | $this->checkReceivedTxtTermsAttachment(); 62 | } 63 | 64 | /** 65 | * @magentoDataFixture Magento/Sales/_files/shipment.php 66 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachpdf 0 67 | */ 68 | public function testWithoutAttachment(): void 69 | { 70 | $this->sendEmail(); 71 | 72 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 73 | self::assertFalse($pdfAttachment); 74 | } 75 | 76 | /** 77 | * @magentoDataFixture Magento/Sales/_files/shipment.php 78 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 79 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachagreement 1 80 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachpdf 1 81 | */ 82 | public function testMultipleAttachments(): void 83 | { 84 | $this->testWithAttachment(); 85 | $this->checkReceivedHtmlTermsAttachment(1, 1); 86 | } 87 | 88 | /** 89 | * @magentoDataFixture Magento/Sales/_files/order_with_shipping_and_invoice.php 90 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachinvoicepdf 1 91 | * @magentoConfigFixture current_store sales_email/shipment_comment/attachpdf 1 92 | */ 93 | public function testInvoicePdfAttachment(): void 94 | { 95 | $this->fixMissingSkuOnInvoiceItem(); 96 | $this->testWithAttachment(); 97 | $allPdfAttachments = $this->getAllAttachmentsOfType( 98 | $this->getLastEmail(), 99 | 'application/pdf' 100 | ); 101 | self::assertCount(2, $allPdfAttachments); 102 | } 103 | 104 | protected function getShipment(): \Magento\Sales\Api\Data\ShipmentInterface 105 | { 106 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 107 | \Magento\Sales\Model\ResourceModel\Order\Shipment\Collection::class 108 | )->setPageSize(1); 109 | $shipment = $collection->getFirstItem(); 110 | foreach ($shipment->getAllItems() as $item) { 111 | if (!$item->getSku()) { 112 | $item->setSku('Test_sku'); 113 | } 114 | } 115 | return $shipment; 116 | } 117 | 118 | /** 119 | * @return \Magento\Sales\Api\Data\ShipmentInterface 120 | */ 121 | protected function sendEmail(): \Magento\Sales\Api\Data\ShipmentInterface 122 | { 123 | $shipment = $this->getShipment(); 124 | $shipmentSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 125 | ->create(\Magento\Sales\Model\Order\Email\Sender\ShipmentCommentSender::class); 126 | 127 | $shipmentSender->send($shipment); 128 | return $shipment; 129 | } 130 | 131 | private function fixMissingSkuOnInvoiceItem(): void 132 | { 133 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 134 | \Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class 135 | )->setPageSize(1); 136 | $invoice = $collection->getFirstItem(); 137 | foreach ($invoice->getAllItems() as $item) { 138 | if (!$item->getSku()) { 139 | $item->setSku('Test_sku'); 140 | } 141 | } 142 | $invoice->save(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/BeforeSendShipmentObserverTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | /** 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | /** 14 | * @magentoAppArea adminhtml 15 | * @magentoAppIsolation enabled 16 | */ 17 | class BeforeSendShipmentObserverTest extends Common 18 | { 19 | /** 20 | * @magentoDataFixture Magento/Sales/_files/shipment.php 21 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 22 | * @magentoAppIsolation enabled 23 | */ 24 | public function testWithAttachment(): \Magento\Sales\Api\Data\ShipmentInterface 25 | { 26 | $shipment = $this->sendEmail(); 27 | $this->comparePdfs($shipment); 28 | return $shipment; 29 | } 30 | 31 | private function comparePdfs($shipment, $number = 1): void 32 | { 33 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 34 | $pdf = $this->objectManager 35 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\ShipmentAdapter::class) 36 | ->getPdfAsString([$shipment]); 37 | $this->comparePdfAsStringWithReceivedPdf( 38 | $pdf, 39 | sprintf('PACKINGSLIP_%s.pdf', $shipment->getIncrementId()), 40 | $number 41 | ); 42 | } else { 43 | $pdf = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 44 | ->create(\Magento\Sales\Model\Order\Pdf\Shipment::class)->getPdf([$shipment]); 45 | $this->compareWithReceivedPdf($pdf, $number); 46 | } 47 | } 48 | 49 | /** 50 | * @magentoDataFixture Magento/Sales/_files/shipment.php 51 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 52 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 53 | */ 54 | public function testWithHtmlTermsAttachment(): void 55 | { 56 | $this->sendEmail(); 57 | $this->checkReceivedHtmlTermsAttachment(); 58 | } 59 | 60 | /** 61 | * @magentoDataFixture Magento/Sales/_files/shipment.php 62 | * @magentoDataFixture Fooman/EmailAttachments/_files/agreement_active_with_text_content.php 63 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 64 | */ 65 | public function testWithTextTermsAttachment(): void 66 | { 67 | $this->sendEmail(); 68 | $this->checkReceivedTxtTermsAttachment(); 69 | } 70 | 71 | /** 72 | * @magentoDataFixture Magento/Sales/_files/shipment.php 73 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 0 74 | */ 75 | public function testWithoutAttachment(): void 76 | { 77 | $this->sendEmail(); 78 | 79 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'application/pdf'); 80 | self::assertFalse($pdfAttachment); 81 | } 82 | 83 | /** 84 | * @magentoDataFixture Magento/Sales/_files/shipment.php 85 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 86 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 87 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 88 | */ 89 | public function testMultipleAttachments(): void 90 | { 91 | $this->testWithAttachment(); 92 | $this->checkReceivedHtmlTermsAttachment(1, 1); 93 | } 94 | 95 | /** 96 | * @magentoDataFixture Magento/Sales/_files/order_with_shipping_and_invoice.php 97 | * @magentoConfigFixture current_store sales_email/shipment/attachinvoicepdf 1 98 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 99 | */ 100 | public function testInvoicePdfAttachment(): void 101 | { 102 | $this->fixMissingSkuOnInvoiceItem(); 103 | $this->testWithAttachment(); 104 | $allPdfAttachments = $this->getAllAttachmentsOfType( 105 | $this->getLastEmail(), 106 | 'application/pdf' 107 | ); 108 | self::assertCount(2, $allPdfAttachments); 109 | } 110 | 111 | /** 112 | * @magentoDataFixture Magento/Sales/_files/shipment.php 113 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 114 | * @magentoAppIsolation enabled 115 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 116 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 117 | * @magentoConfigFixture current_store sales_email/shipment/copy_method copy 118 | * @magentoConfigFixture current_store sales_email/shipment/copy_to copyto@example.com 119 | */ 120 | public function testWithCopyToRecipient(): void 121 | { 122 | $shipment = $this->testWithAttachment(); 123 | $this->checkReceivedHtmlTermsAttachment(1, 1); 124 | $this->checkReceivedHtmlTermsAttachment(2, 1); 125 | $this->comparePdfs($shipment, 1); 126 | } 127 | 128 | /** 129 | * @magentoDataFixture Magento/Sales/_files/shipment.php 130 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 131 | * @magentoAppIsolation enabled 132 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 133 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 134 | * @magentoConfigFixture current_store sales_email/shipment/copy_method copy 135 | * @magentoConfigFixture current_store sales_email/shipment/copy_to copyto@example.com 136 | */ 137 | public function testWithMultipleCopyToRecipients(): void 138 | { 139 | $shipment = $this->testWithAttachment(); 140 | $this->checkReceivedHtmlTermsAttachment(1, 1); 141 | $this->checkReceivedHtmlTermsAttachment(2, 1); 142 | //$this->checkReceivedHtmlTermsAttachment(3, 1); 143 | $this->comparePdfs($shipment, 1); 144 | $mail = $this->getLastEmail(); 145 | 146 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 147 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 148 | self::assertCount(2, $allPdfAttachments); 149 | } else { 150 | self::assertCount(1, $allPdfAttachments); 151 | } 152 | } 153 | 154 | /** 155 | * @magentoDataFixture Magento/Sales/_files/shipment.php 156 | * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php 157 | * @magentoAppIsolation enabled 158 | * @magentoConfigFixture current_store sales_email/shipment/attachagreement 1 159 | * @magentoConfigFixture current_store sales_email/shipment/attachpdf 1 160 | * @magentoConfigFixture current_store sales_email/shipment/copy_method bcc 161 | * @magentoConfigFixture current_store sales_email/shipment/copy_to copyto@example.com 162 | */ 163 | public function testWithBccRecipient(): void 164 | { 165 | $this->testWithAttachment(); 166 | $this->checkReceivedHtmlTermsAttachment(1, 1); 167 | $mail = $this->getLastEmail(); 168 | self::assertEquals('copyto@example.com', $mail['Bcc'][0]['Address']); 169 | 170 | $allPdfAttachments = $this->getAllAttachmentsOfType($mail, 'application/pdf'); 171 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 172 | self::assertCount(2, $allPdfAttachments); 173 | } else { 174 | self::assertCount(1, $allPdfAttachments); 175 | } 176 | } 177 | 178 | protected function getShipment(): \Magento\Sales\Api\Data\ShipmentInterface 179 | { 180 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 181 | \Magento\Sales\Model\ResourceModel\Order\Shipment\Collection::class 182 | )->setPageSize(1); 183 | $shipment = $collection->getFirstItem(); 184 | foreach ($shipment->getAllItems() as $item) { 185 | if (!$item->getSku()) { 186 | $item->setSku('Test_sku'); 187 | } 188 | } 189 | return $shipment; 190 | } 191 | 192 | /** 193 | * @return \Magento\Sales\Api\Data\ShipmentInterface 194 | */ 195 | protected function sendEmail(): \Magento\Sales\Api\Data\ShipmentInterface 196 | { 197 | $shipment = $this->getShipment(); 198 | $shipmentSender = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() 199 | ->create(\Magento\Sales\Model\Order\Email\Sender\ShipmentSender::class); 200 | 201 | $shipmentSender->send($shipment); 202 | return $shipment; 203 | } 204 | 205 | private function fixMissingSkuOnInvoiceItem(): void 206 | { 207 | $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 208 | \Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class 209 | )->setPageSize(1); 210 | $invoice = $collection->getFirstItem(); 211 | foreach ($invoice->getAllItems() as $item) { 212 | if (!$item->getSku()) { 213 | $item->setSku('Test_sku'); 214 | } 215 | } 216 | $invoice->save(); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/Observer/Common.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | namespace Fooman\EmailAttachments\Observer; 5 | 6 | use Fooman\EmailAttachments\TransportBuilder; 7 | use Yoast\PHPUnitPolyfills\TestCases\TestCase; 8 | 9 | /** 10 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 11 | * 12 | * For the full copyright and license information, please view the LICENSE 13 | * file that was distributed with this source code. 14 | */ 15 | class Common extends TestCase 16 | { 17 | protected $apiClient; 18 | protected $objectManager; 19 | protected $moduleManager; 20 | 21 | const BASE_URL = 'http://127.0.0.1:8025/api/'; 22 | 23 | protected function setUp(): void 24 | { 25 | parent::setUp(); 26 | $this->apiClient = new \GuzzleHttp\Client(); 27 | $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); 28 | $this->objectManager->configure( 29 | ['preferences' => 30 | [ 31 | \Magento\Framework\Mail\TransportInterface::class => \Magento\Email\Model\Transport::class, 32 | \Magento\Framework\Mail\Template\TransportBuilder::class => TransportBuilder::class 33 | ] 34 | ] 35 | ); 36 | 37 | $this->moduleManager = $this->objectManager->create(\Magento\Framework\Module\Manager::class); 38 | } 39 | 40 | public function getLastEmail($number = 1) 41 | { 42 | $result = $this->apiClient->request('GET', self::BASE_URL . 'v1/messages?limit=' . $number); 43 | $messages = json_decode((string)$result->getBody(), true); 44 | $lastEmailId = $messages['messages'][$number - 1]['ID']; 45 | $result = $this->apiClient->request('GET',self::BASE_URL . 'v1/message/' . $lastEmailId); 46 | return json_decode((string)$result->getBody(), true); 47 | } 48 | 49 | public function getAttachmentOfType($email, $type) 50 | { 51 | if (isset($email['Attachments'])) { 52 | foreach ($email['Attachments'] as $part) { 53 | if (!isset($type, $part['ContentType'])) { 54 | continue; 55 | } 56 | if ($part['ContentType'] == $type) { 57 | $result = $this->apiClient->request( 58 | 'GET', 59 | self::BASE_URL . 'v1/message/'.$email['ID'].'/part/'.$part['PartID'] 60 | ); 61 | $part['Body'] = $result->getBody()->getContents(); 62 | return $part; 63 | } 64 | } 65 | } 66 | 67 | return false; 68 | } 69 | 70 | public function getAllAttachmentsOfType($email, $type) 71 | { 72 | $parts = []; 73 | if (isset($email['Attachments'])) { 74 | foreach ($email['Attachments'] as $part) { 75 | if (!isset($type, $part['ContentType'])) { 76 | continue; 77 | } 78 | if ($part['ContentType'] == $type) { 79 | $result = $this->apiClient->request( 80 | 'GET', 81 | self::BASE_URL . 'v1/message/'.$email['ID'].'/part/'.$part['PartID'] 82 | ); 83 | $part['Body'] = $result->getBody()->getContents(); 84 | $parts[] = $part; 85 | } 86 | } 87 | } 88 | 89 | return $parts; 90 | } 91 | 92 | /** 93 | * @param $pdf 94 | * @param $number 95 | */ 96 | protected function compareWithReceivedPdf($pdf, $number = 1): void 97 | { 98 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail($number), 'application/pdf'); 99 | self::assertEquals(strlen($pdf->render()), strlen($pdfAttachment['Body'])); 100 | } 101 | 102 | /** 103 | * @param $pdf 104 | * @param bool $title 105 | * @param $number 106 | */ 107 | protected function comparePdfAsStringWithReceivedPdf($pdf, $title = false, $number = 1): void 108 | { 109 | $pdfAttachment = $this->getAttachmentOfType($this->getLastEmail($number), 'application/pdf'); 110 | self::assertEquals(strlen($pdf), strlen($pdfAttachment['Body'])); 111 | if ($title !== false) { 112 | self::assertEquals($title, $this->extractFilename($pdfAttachment)); 113 | } 114 | } 115 | 116 | protected function checkReceivedHtmlTermsAttachment($number = 1, $attachmentIndex = 0): void 117 | { 118 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 119 | $pdfs = $this->getAllAttachmentsOfType($this->getLastEmail($number), 'application/pdf'); 120 | self::assertEquals( 121 | strlen($this->getExpectedPdfAgreementsString()), 122 | strlen($pdfs[$attachmentIndex]['Body']) 123 | ); 124 | } else { 125 | $found = false; 126 | $termsAttachments = $this->getAllAttachmentsOfType( 127 | $this->getLastEmail($number), 128 | 'text/html' 129 | ); 130 | foreach ($termsAttachments as $termsAttachment) { 131 | if (strpos( 132 | $termsAttachment['Body'], 133 | 'Checkout agreement content: <b>HTML</b>' 134 | ) !== false) { 135 | $found = true; 136 | } 137 | } 138 | self::assertTrue($found); 139 | } 140 | } 141 | 142 | protected function checkReceivedTxtTermsAttachment($number = 1, $attachmentIndex = 0): void 143 | { 144 | if ($this->moduleManager->isEnabled('Fooman_PdfCustomiser')) { 145 | $pdfs = $this->getAllAttachmentsOfType($this->getLastEmail($number), 'application/pdf'); 146 | self::assertEquals( 147 | strlen($this->getExpectedPdfAgreementsString()), 148 | strlen($pdfs[$attachmentIndex]['Body']) 149 | ); 150 | } else { 151 | $termsAttachment = $this->getAttachmentOfType($this->getLastEmail($number), 'text/plain'); 152 | self::assertStringContainsString( 153 | 'Checkout agreement content: TEXT', 154 | $termsAttachment['Body'] 155 | ); 156 | } 157 | } 158 | 159 | protected function extractFilename($input) 160 | { 161 | return $input['FileName']; 162 | } 163 | 164 | protected function getExpectedPdfAgreementsString() 165 | { 166 | $termsCollection = $this->objectManager->create( 167 | \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection::class 168 | ); 169 | $termsCollection->addStoreFilter(1)->addFieldToFilter('is_active', 1); 170 | $agreements = []; 171 | foreach ($termsCollection as $agreement) { 172 | $agreements[] = $agreement->setStoreId(1); 173 | } 174 | 175 | return $this->objectManager 176 | ->create(\Fooman\PdfCustomiser\Model\PdfRenderer\TermsAndConditionsAdapter::class) 177 | ->getPdfAsString($agreements); 178 | } 179 | 180 | protected function tearDown(): void 181 | { 182 | $this->apiClient->request('DELETE', self::BASE_URL . 'v1/messages'); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/TransportBuilder.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | /** 5 | * @author Kristof Ringleff 6 | * @package Fooman_EmailAttachments 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | namespace Fooman\EmailAttachments; 13 | 14 | class TransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /tests/integration/testsuite/Fooman/EmailAttachments/_files/agreement_active_with_text_content.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | require __DIR__.'/../../../Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php'; 5 | 6 | $agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); 7 | $agreement->load('Checkout Agreement (inactive)', 'name'); 8 | $agreement->setIsActive("1"); 9 | $agreement->setName('Checkout Agreement'); 10 | $agreement->setStores([0,1]); 11 | $agreement->save(); 12 | -------------------------------------------------------------------------------- /tests/unit/bootstrap.php: -------------------------------------------------------------------------------- 1 | <?php 2 | use Fooman\UnittestSetup\Magento2UnitTestSetup; 3 | /** 4 | * @copyright Copyright (c) 2016 Fooman Limited (http://www.fooman.co.nz) 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | require (__DIR__.'/../../vendor/autoload.php'); 11 | $unitTestSetup = new Magento2UnitTestSetup(); 12 | $unitTestSetup->run(); 13 | -------------------------------------------------------------------------------- /tests/unit/testsuite/Fooman/EmailAttachments/UnitTest/Model/AttachmentContainerTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | /** 5 | * @author Kristof Ringleff 6 | * @package Fooman_EmailAttachments 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | namespace Fooman\EmailAttachments\Test\Unit\Model; 13 | 14 | use Yoast\PHPUnitPolyfills\TestCases\TestCase; 15 | 16 | class AttachmentContainerTest extends TestCase 17 | { 18 | private const TEST_CONTENT = 'Testing content'; 19 | private const TEST_MIME = 'text/plain'; 20 | private const TEST_FILENAME = 'filename.txt'; 21 | private const TEST_SECOND_FILENAME = 'filename2.txt'; 22 | private const TEST_DISPOSITION = 'Disposition'; 23 | private const TEST_ENCODING = 'ENCODING'; 24 | 25 | /** 26 | * @var \Fooman\EmailAttachments\Model\AttachmentContainer 27 | */ 28 | protected $attachmentContainer; 29 | 30 | /** 31 | * @var \Fooman\EmailAttachments\Model\Attachment 32 | */ 33 | protected $attachment; 34 | 35 | /** 36 | * @var \Fooman\EmailAttachments\Model\Attachment 37 | */ 38 | protected $secondAttachment; 39 | 40 | protected function setUp(): void 41 | { 42 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 43 | $this->attachment = $objectManager->getObject( 44 | \Fooman\EmailAttachments\Model\Attachment::class, 45 | [ 46 | 'content' => self::TEST_CONTENT, 47 | 'mimeType' => self::TEST_MIME, 48 | 'fileName' => self::TEST_FILENAME, 49 | 'disposition' => self::TEST_DISPOSITION, 50 | 'encoding' => self::TEST_ENCODING 51 | ] 52 | ); 53 | $this->secondAttachment = $objectManager->getObject( 54 | \Fooman\EmailAttachments\Model\Attachment::class, 55 | [ 56 | 'content' => self::TEST_CONTENT, 57 | 'mimeType' => self::TEST_MIME, 58 | 'fileName' => self::TEST_SECOND_FILENAME, 59 | 'disposition' => self::TEST_DISPOSITION, 60 | 'encoding' => self::TEST_ENCODING 61 | ] 62 | ); 63 | $this->attachmentContainer = $objectManager->getObject( 64 | \Fooman\EmailAttachments\Model\AttachmentContainer::class 65 | ); 66 | $this->attachmentContainer->resetAttachments(); 67 | } 68 | 69 | public function testHasAttachments(): void 70 | { 71 | self::assertFalse($this->attachmentContainer->hasAttachments()); 72 | $this->attachmentContainer->addAttachment($this->attachment); 73 | self::assertTrue($this->attachmentContainer->hasAttachments()); 74 | } 75 | 76 | public function testResetAttachments(): void 77 | { 78 | $this->attachmentContainer->addAttachment($this->attachment); 79 | self::assertTrue($this->attachmentContainer->hasAttachments()); 80 | $this->attachmentContainer->resetAttachments(); 81 | self::assertFalse($this->attachmentContainer->hasAttachments()); 82 | } 83 | 84 | public function testAttachments(): void 85 | { 86 | $this->attachmentContainer->addAttachment($this->attachment); 87 | self::assertEquals([$this->attachment], $this->attachmentContainer->getAttachments()); 88 | } 89 | 90 | public function testDoubleAttachments(): void 91 | { 92 | $this->attachmentContainer->addAttachment($this->attachment); 93 | $this->attachmentContainer->addAttachment($this->attachment); 94 | self::assertEquals([$this->attachment], $this->attachmentContainer->getAttachments()); 95 | } 96 | 97 | public function testTwoAttachments(): void 98 | { 99 | $this->attachmentContainer->addAttachment($this->attachment); 100 | $this->attachmentContainer->addAttachment($this->secondAttachment); 101 | self::assertEquals([$this->attachment, $this->secondAttachment], $this->attachmentContainer->getAttachments()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tests/unit/testsuite/Fooman/EmailAttachments/UnitTest/Model/AttachmentTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | declare(strict_types=1); 3 | 4 | /** 5 | * @author Kristof Ringleff 6 | * @package Fooman_EmailAttachments 7 | * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | namespace Fooman\EmailAttachments\Test\Unit\Model; 13 | 14 | use Yoast\PHPUnitPolyfills\TestCases\TestCase; 15 | 16 | class AttachmentTest extends TestCase 17 | { 18 | private const TEST_CONTENT = 'Testing content'; 19 | private const TEST_MIME = 'text/plain'; 20 | private const TEST_FILENAME = 'filename.txt'; 21 | private const TEST_DISPOSITION = 'Disposition'; 22 | private const TEST_ENCODING = 'ENCODING'; 23 | 24 | /** 25 | * @var \Fooman\EmailAttachments\Model\Attachment 26 | */ 27 | protected $attachment; 28 | 29 | protected function setUp(): void 30 | { 31 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 32 | $this->attachment = $objectManager->getObject( 33 | \Fooman\EmailAttachments\Model\Attachment::class, 34 | [ 35 | 'content' => self::TEST_CONTENT, 36 | 'mimeType' => self::TEST_MIME, 37 | 'fileName' => self::TEST_FILENAME, 38 | 'disposition' => self::TEST_DISPOSITION, 39 | 'encoding' => self::TEST_ENCODING 40 | ] 41 | ); 42 | } 43 | 44 | public function testGetContent(): void 45 | { 46 | self::assertEquals(self::TEST_CONTENT, $this->attachment->getContent()); 47 | } 48 | 49 | public function testGetMime(): void 50 | { 51 | self::assertEquals(self::TEST_MIME, $this->attachment->getMimeType()); 52 | } 53 | 54 | public function testGetFilename(): void 55 | { 56 | self::assertEquals(self::TEST_FILENAME, $this->attachment->getFilename()); 57 | } 58 | 59 | public function testGetDispositon(): void 60 | { 61 | self::assertEquals(self::TEST_DISPOSITION, $this->attachment->getDisposition()); 62 | } 63 | 64 | public function testGetEncoding(): void 65 | { 66 | self::assertEquals(self::TEST_ENCODING, $this->attachment->getEncoding()); 67 | } 68 | } 69 | --------------------------------------------------------------------------------