From 63fc317578df0c764a04727a02dc18d1656781a9 Mon Sep 17 00:00:00 2001 From: shin Date: Thu, 29 Oct 2020 15:12:51 +0700 Subject: [PATCH 1/2] =?UTF-8?q?L=E1=BB=97i=20content=20v=C3=A0=20attached?= =?UTF-8?q?=20file=20khi=20g=E1=BB=ADi=20email=20nhi=E1=BB=81u=20orders=20?= =?UTF-8?q?qua=20cron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/MailEvent.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Model/MailEvent.php b/Model/MailEvent.php index 61be9fb..7a06d2f 100644 --- a/Model/MailEvent.php +++ b/Model/MailEvent.php @@ -144,15 +144,18 @@ public function dispatch($message) if ($this->dataHelper->isEnabledAttachPdf($storeId) && in_array($emailType, $this->dataHelper->getAttachPdf($storeId), true)) { $this->setPdfAttachment($emailType, $message, $obj, $attachmentPDF); + $attachmentPDF = true; } if ($this->dataHelper->getTacFile($storeId) && in_array($emailType, $this->dataHelper->getAttachTac($storeId), true)) { $this->setTACAttachment($message, $storeId); + $attachmentPDF = true; } - if ($this->dataHelper->versionCompare('2.2.9')) { + if ($this->dataHelper->versionCompare('2.2.9') && $attachmentPDF) { $this->setBodyAttachment($message); + $this->parts = []; } foreach ($this->dataHelper->getCcTo($storeId) as $email) { From 4452d154c28657c780d21748661e9b81d4d88254 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 10 Nov 2020 15:39:19 +0700 Subject: [PATCH 2/2] Clean code --- .github/ISSUE_TEMPLATE/bug_report.md | 68 +++++++++---------- .../developer-experience-issue.md | 38 +++++------ .github/ISSUE_TEMPLATE/feature_request.md | 44 ++++++------ .github/PULL_REQUEST_TEMPLATE.md | 38 +++++------ .github/no-response.yml | 26 +++---- Helper/Data.php | 4 +- Mail/EmailMessage.php | 6 +- Mail/Transport.php | 4 +- Model/Config/Source/AttachPdf.php | 8 +-- Model/Config/Source/AttachTaC.php | 12 ++-- Model/MailEvent.php | 40 +++++------ composer.json | 52 +++++++------- i18n/en_US.csv | 42 ++++++------ 13 files changed, 191 insertions(+), 191 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 65788ed..dafbad1 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,34 +1,34 @@ ---- -name: Bug report -about: Technical issue with the extension -labels: 'Issue' - ---- - - - -### Preconditions (*) - -1. -2. - -### Steps to reproduce (*) - -1. -2. - -### Expected result (*) - -1. [Screenshots, logs or description] -2. - -### Actual result (*) - -1. [Screenshots, logs or description] -2. +--- +name: Bug report +about: Technical issue with the extension +labels: 'Issue' + +--- + + + +### Preconditions (*) + +1. +2. + +### Steps to reproduce (*) + +1. +2. + +### Expected result (*) + +1. [Screenshots, logs or description] +2. + +### Actual result (*) + +1. [Screenshots, logs or description] +2. diff --git a/.github/ISSUE_TEMPLATE/developer-experience-issue.md b/.github/ISSUE_TEMPLATE/developer-experience-issue.md index 90a4fb5..597f869 100644 --- a/.github/ISSUE_TEMPLATE/developer-experience-issue.md +++ b/.github/ISSUE_TEMPLATE/developer-experience-issue.md @@ -1,19 +1,19 @@ ---- -name: Developer experience issue -about: Issues related to customization, extensibility, modularity -labels: 'Experience' - ---- - - - -### Summary (*) - - -### Examples (*) - - -### Proposed solution - +--- +name: Developer experience issue +about: Issues related to customization, extensibility, modularity +labels: 'Experience' + +--- + + + +### Summary (*) + + +### Examples (*) + + +### Proposed solution + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 3cd5bb4..c7708c5 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,22 +1,22 @@ ---- -name: Feature request -about: Request feature for development -labels: 'Feature Request' - ---- - - - -### Description (*) - - -### Expected behavior (*) - - -### Benefits - - -### Additional information - +--- +name: Feature request +about: Request feature for development +labels: 'Feature Request' + +--- + + + +### Description (*) + + +### Expected behavior (*) + + +### Benefits + + +### Additional information + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8f862f9..6b8e961 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,19 +1,19 @@ - - -### Description - - -### Fixed Issues (if relevant) - -1. https://github.com/mageplaza/magento-2-reports/: Issue title -2. ... - -### Manual testing scenarios - -1. -2. - -### Contribution checklist - - [ ] Pull request has a meaningful description of its purpose - - [ ] All commits are accompanied by meaningful commit messages - - [ ] All new or changed code is covered with unit/integration tests (if applicable) + + +### Description + + +### Fixed Issues (if relevant) + +1. https://github.com/mageplaza/magento-2-reports/: Issue title +2. ... + +### Manual testing scenarios + +1. +2. + +### Contribution checklist + - [ ] Pull request has a meaningful description of its purpose + - [ ] All commits are accompanied by meaningful commit messages + - [ ] All new or changed code is covered with unit/integration tests (if applicable) diff --git a/.github/no-response.yml b/.github/no-response.yml index 06a2899..64568da 100644 --- a/.github/no-response.yml +++ b/.github/no-response.yml @@ -1,13 +1,13 @@ -# Configuration for probot-no-response - https://github.com/probot/no-response - -# Number of days of inactivity before an Issue is closed for lack of response -daysUntilClose: 7 -# Label requiring a response -responseRequiredLabel: waiting-customer-response -# Comment to post when closing an Issue for lack of response. Set to `false` to disable -closeComment: > - This issue has been automatically closed because there has been no response - to our request for more information from the original author. With only the - information that is currently in the issue, we don't have enough information - to take action. Please reach out if you have or find the answers we need so - that we can investigate further. +# Configuration for probot-no-response - https://github.com/probot/no-response + +# Number of days of inactivity before an Issue is closed for lack of response +daysUntilClose: 7 +# Label requiring a response +responseRequiredLabel: waiting-customer-response +# Comment to post when closing an Issue for lack of response. Set to `false` to disable +closeComment: > + This issue has been automatically closed because there has been no response + to our request for more information from the original author. With only the + information that is currently in the issue, we don't have enough information + to take action. Please reach out if you have or find the answers we need so + that we can investigate further. diff --git a/Helper/Data.php b/Helper/Data.php index bddc4a8..124663c 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -62,7 +62,7 @@ public function getBccTo($store = null) */ public function isEnabledAttachPdf($store = null) { - return (bool) $this->getConfigGeneral('is_enabled_attach_pdf', $store); + return (bool)$this->getConfigGeneral('is_enabled_attach_pdf', $store); } /** @@ -84,7 +84,7 @@ public function getAttachPdf($store = null) */ public function isEnabledAttachTac($store = null) { - return (bool) $this->getConfigGeneral('is_enabled_attach_tac', $store); + return (bool)$this->getConfigGeneral('is_enabled_attach_tac', $store); } /** diff --git a/Mail/EmailMessage.php b/Mail/EmailMessage.php index 393e576..a0d936f 100644 --- a/Mail/EmailMessage.php +++ b/Mail/EmailMessage.php @@ -89,7 +89,7 @@ public function __construct( $encoding = '' ) { $this->message = new ZendMessage(); - $mimeMessage = new ZendMimeMessage(); + $mimeMessage = new ZendMimeMessage(); $mimeMessage->setParts($body->getParts()); $this->message->setBody($mimeMessage); if ($encoding) { @@ -198,7 +198,7 @@ public function getSender() return $this->addressFactory->create( [ 'email' => $zendSender->getEmail(), - 'name' => $zendSender->getName() + 'name' => $zendSender->getName() ] ); } @@ -260,7 +260,7 @@ private function convertAddressListToAddressArray(AddressList $addressList) $this->addressFactory->create( [ 'email' => $address->getEmail(), - 'name' => $address->getName() + 'name' => $address->getName() ] ); } diff --git a/Mail/Transport.php b/Mail/Transport.php index 00fb235..a5440a6 100644 --- a/Mail/Transport.php +++ b/Mail/Transport.php @@ -77,7 +77,7 @@ public function __construct( ScopeConfigInterface $scopeConfig, $parameters = null ) { - $this->isSetReturnPath = (int) $scopeConfig->getValue( + $this->isSetReturnPath = (int)$scopeConfig->getValue( self::XML_PATH_SENDING_SET_RETURN_PATH, ScopeInterface::SCOPE_STORE ); @@ -87,7 +87,7 @@ public function __construct( ); $this->zendTransport = new Sendmail($parameters); - $this->message = $message; + $this->message = $message; } /** diff --git a/Model/Config/Source/AttachPdf.php b/Model/Config/Source/AttachPdf.php index 44b4667..00f7071 100644 --- a/Model/Config/Source/AttachPdf.php +++ b/Model/Config/Source/AttachPdf.php @@ -29,8 +29,8 @@ */ class AttachPdf implements OptionSourceInterface { - const INVOICE = 'invoice'; - const SHIPMENT = 'shipment'; + const INVOICE = 'invoice'; + const SHIPMENT = 'shipment'; const CREDIT_MEMO = 'creditmemo'; /** @@ -41,8 +41,8 @@ class AttachPdf implements OptionSourceInterface public static function getOptionArray() { return [ - self::INVOICE => __('Invoice'), - self::SHIPMENT => __('Shipment'), + self::INVOICE => __('Invoice'), + self::SHIPMENT => __('Shipment'), self::CREDIT_MEMO => __('Credit Memo') ]; } diff --git a/Model/Config/Source/AttachTaC.php b/Model/Config/Source/AttachTaC.php index 3b2d285..6c8ab79 100644 --- a/Model/Config/Source/AttachTaC.php +++ b/Model/Config/Source/AttachTaC.php @@ -29,9 +29,9 @@ */ class AttachTaC implements OptionSourceInterface { - const ORDER = 'order'; - const INVOICE = 'invoice'; - const SHIPMENT = 'shipment'; + const ORDER = 'order'; + const INVOICE = 'invoice'; + const SHIPMENT = 'shipment'; const CREDIT_MEMO = 'creditmemo'; /** @@ -42,9 +42,9 @@ class AttachTaC implements OptionSourceInterface public static function getOptionArray() { return [ - self::ORDER => __('Order'), - self::INVOICE => __('Invoice'), - self::SHIPMENT => __('Shipment'), + self::ORDER => __('Order'), + self::INVOICE => __('Invoice'), + self::SHIPMENT => __('Shipment'), self::CREDIT_MEMO => __('Credit Memo') ]; } diff --git a/Model/MailEvent.php b/Model/MailEvent.php index 7a06d2f..641e898 100644 --- a/Model/MailEvent.php +++ b/Model/MailEvent.php @@ -51,9 +51,9 @@ class MailEvent * @var array */ const MIME_TYPES = [ - 'txt' => 'text/plain', - 'pdf' => 'application/pdf', - 'doc' => 'application/msword', + 'txt' => 'text/plain', + 'pdf' => 'application/pdf', + 'doc' => 'application/msword', 'docx' => 'application/msword', ]; @@ -103,11 +103,11 @@ public function __construct( ObjectManagerInterface $objectManager, SessionManagerInterface $coreSession ) { - $this->mail = $mail; - $this->dataHelper = $dataHelper; - $this->filesystem = $filesystem; + $this->mail = $mail; + $this->dataHelper = $dataHelper; + $this->filesystem = $filesystem; $this->objectManager = $objectManager; - $this->coreSession = $coreSession; + $this->coreSession = $coreSession; } /** @@ -122,7 +122,7 @@ public function dispatch($message) return; } /** @var Store|null $store */ - $store = isset($templateVars['store']) ? $templateVars['store'] : null; + $store = isset($templateVars['store']) ? $templateVars['store'] : null; $storeId = $store ? $store->getId() : null; if (!$this->dataHelper->isEnabled($storeId)) { @@ -207,11 +207,11 @@ private function setPdfAttachment($emailType, $message, $obj, $attachmentPDF = n $pdf = $this->objectManager->create($pdfModel)->getPdf([$obj]); if ($this->dataHelper->versionCompare('2.2.9')) { - $attachment = new Part($pdf->render()); - $attachment->type = 'application/pdf'; - $attachment->encoding = Zend_Mime::ENCODING_BASE64; + $attachment = new Part($pdf->render()); + $attachment->type = 'application/pdf'; + $attachment->encoding = Zend_Mime::ENCODING_BASE64; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; - $attachment->filename = $emailType . $obj->getIncrementId() . '.pdf'; + $attachment->filename = $emailType . $obj->getIncrementId() . '.pdf'; $this->parts[] = $attachment; @@ -236,11 +236,11 @@ private function setTACAttachment($message, $storeId = null) [$content, $ext, $mimeType] = $this->getTacFile($storeId); if ($this->dataHelper->versionCompare('2.2.9')) { - $attachment = new Part($content); - $attachment->type = $mimeType; - $attachment->encoding = Zend_Mime::ENCODING_BASE64; + $attachment = new Part($content); + $attachment->type = $mimeType; + $attachment->encoding = Zend_Mime::ENCODING_BASE64; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; - $attachment->filename = __('terms_and_conditions') . '.' . $ext; + $attachment->filename = __('terms_and_conditions') . '.' . $ext; $this->parts[] = $attachment; @@ -289,10 +289,10 @@ private function setBodyAttachment($message) private function getTacFile($storeId = null) { $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); - $tacPath = $this->dataHelper->getTacFile($storeId); - $filePath = $mediaDirectory->getAbsolutePath('mageplaza/email_attachments/' . $tacPath); - $content = file_get_contents($filePath); - $ext = (string) substr($filePath, strrpos($filePath, '.') + 1); + $tacPath = $this->dataHelper->getTacFile($storeId); + $filePath = $mediaDirectory->getAbsolutePath('mageplaza/email_attachments/' . $tacPath); + $content = file_get_contents($filePath); + $ext = (string)substr($filePath, strrpos($filePath, '.') + 1); return [$content, $ext, self::MIME_TYPES[$ext]]; } diff --git a/composer.json b/composer.json index 6c1754e..4a2c70d 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,26 @@ -{ - "name": "mageplaza/module-email-attachments", - "description": "Magento 2 Email Attachments Extension", - "require": { - "mageplaza/module-core": "^1.4.5" - }, - "type": "magento2-module", - "version": "1.0.5", - "license": "proprietary", - "authors": [ - { - "name": "Mageplaza", - "email": "support@mageplaza.com", - "homepage": "https://www.mageplaza.com", - "role": "Technical Support" - } - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Mageplaza\\EmailAttachments\\": "" - } - } -} +{ + "name": "mageplaza/module-email-attachments", + "description": "Magento 2 Email Attachments Extension", + "require": { + "mageplaza/module-core": "^1.4.5" + }, + "type": "magento2-module", + "version": "4.0.0", + "license": "proprietary", + "authors": [ + { + "name": "Mageplaza", + "email": "support@mageplaza.com", + "homepage": "https://www.mageplaza.com", + "role": "Technical Support" + } + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mageplaza\\EmailAttachments\\": "" + } + } +} diff --git a/i18n/en_US.csv b/i18n/en_US.csv index c514295..6dfb56a 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -1,21 +1,21 @@ -"Invalid email format.","Invalid email format." -Invoice,Invoice -Shipment,Shipment -"Credit Memo","Credit Memo" -Order,Order -terms_and_conditions,terms_and_conditions -"Email Attachments","Email Attachments" -"General Configuration","General Configuration" -Enable,Enable -"Select Yes to enable the module.","Select Yes to enable the module." -"CC to Emails","CC to Emails" -Comma-separated,Comma-separated -"BCC to Emails","BCC to Emails" -"Enable Attach PDF","Enable Attach PDF" -"Attach PDF file for","Attach PDF file for" -"PDF files for the above billing document(s) will be generated and attached to emails.","PDF files for the above billing document(s) will be generated and attached to emails." -"Enable Attach Terms and Conditions","Enable Attach Terms and Conditions" -"Attach Terms and Conditions to","Attach Terms and Conditions to" -"'Terms and Conditions' will be attached to the above billing document(s) as a file.","'Terms and Conditions' will be attached to the above billing document(s) as a file." -"Terms and Conditions file","Terms and Conditions file" -"Allowed upload file types: .pdf, .doc, .docx, .txt","Allowed upload file types: .pdf, .doc, .docx, .txt" +"Invalid email format.","Invalid email format." +Invoice,Invoice +Shipment,Shipment +"Credit Memo","Credit Memo" +Order,Order +terms_and_conditions,terms_and_conditions +"Email Attachments","Email Attachments" +"General Configuration","General Configuration" +Enable,Enable +"Select Yes to enable the module.","Select Yes to enable the module." +"CC to Emails","CC to Emails" +Comma-separated,Comma-separated +"BCC to Emails","BCC to Emails" +"Enable Attach PDF","Enable Attach PDF" +"Attach PDF file for","Attach PDF file for" +"PDF files for the above billing document(s) will be generated and attached to emails.","PDF files for the above billing document(s) will be generated and attached to emails." +"Enable Attach Terms and Conditions","Enable Attach Terms and Conditions" +"Attach Terms and Conditions to","Attach Terms and Conditions to" +"'Terms and Conditions' will be attached to the above billing document(s) as a file.","'Terms and Conditions' will be attached to the above billing document(s) as a file." +"Terms and Conditions file","Terms and Conditions file" +"Allowed upload file types: .pdf, .doc, .docx, .txt","Allowed upload file types: .pdf, .doc, .docx, .txt"