Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jun 23, 2020
2 parents 9281796 + 016de26 commit 1cf31fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
21 changes: 13 additions & 8 deletions Model/MailEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ public function dispatch($message)
/** @var Order|Invoice|Shipment|Creditmemo $obj */
$obj = $templateVars[$emailType];

if (in_array($emailType, $this->dataHelper->getAttachPdf($storeId), true)) {
if ($this->dataHelper->isEnabledAttachPdf($storeId)
&& in_array($emailType, $this->dataHelper->getAttachPdf($storeId), true)) {
$this->setPdfAttachment($emailType, $message, $obj);
}

if ($this->dataHelper->getTacFile($storeId)
&& in_array($emailType, $this->dataHelper->getAttachTac($storeId), true)) {
$this->setTACAttachment($message);
$this->setTACAttachment($message, $storeId);
}

if ($this->dataHelper->versionCompare('2.2.9')) {
Expand Down Expand Up @@ -203,17 +204,18 @@ private function setPdfAttachment($emailType, $message, $obj)

/**
* @param MailMessageInterface|Zend_Mail $message
* @param null $storeId
*/
private function setTACAttachment($message)
private function setTACAttachment($message, $storeId = null)
{
list($content, $ext, $mimeType) = $this->getTacFile();
[$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->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->filename = 'terms_and_conditions.' . $ext;
$attachment->filename = __('terms_and_conditions') . '.' . $ext;

$this->parts[] = $attachment;

Expand All @@ -225,7 +227,7 @@ private function setTACAttachment($message)
$mimeType,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'terms_and_conditions.' . $ext
__('terms_and_conditions') . '.' . $ext
);
}

Expand All @@ -241,6 +243,7 @@ private function setBodyAttachment($message)

$part = new Part($body);
$part->setCharset('utf-8');
$part->setEncoding(Mime::ENCODING_BASE64);
if ($this->dataHelper->versionCompare('2.3.3')) {
$part->setEncoding(Mime::ENCODING_QUOTEDPRINTABLE);
$part->setDisposition(Mime::DISPOSITION_INLINE);
Expand All @@ -254,12 +257,14 @@ private function setBodyAttachment($message)
}

/**
* @param null $storeId
*
* @return array
*/
private function getTacFile()
private function getTacFile($storeId = null)
{
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$tacPath = $this->dataHelper->getTacFile();
$tacPath = $this->dataHelper->getTacFile($storeId);
$filePath = $mediaDirectory->getAbsolutePath('mageplaza/email_attachments/' . $tacPath);
$content = file_get_contents($filePath);
$ext = (string) substr($filePath, strrpos($filePath, '.') + 1);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "1.0.3",
"version": "1.0.4",
"license": "proprietary",
"authors": [
{
Expand Down
1 change: 1 addition & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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
Expand Down

0 comments on commit 1cf31fc

Please sign in to comment.