PHP code example of webqam / magento2-module-emailattachment
1. Go to this page and download the library: Download webqam/magento2-module-emailattachment library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webqam / magento2-module-emailattachment example snippets
use Magento\Framework\DataObject;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Webqam\EmailAttachment\Model\Order\Email\Container\AttachmentIdentityInterface;
class OrderSetTemplateVarsBefore implements ObserverInterface
{
/**
* Execute observer
*
* @param Observer $observer
* @return void
*/
public function execute(
Observer $observer
) {
/** @var DataObject $transportObject */
$transportObject = $observer->getDataByKey('transportObject');
$attachments = $transportObject->getDataByKey(
AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA
);
$attachment = [
AttachmentIdentityInterface::KEY_ATTACHMENT_CONTENT => 'content',
AttachmentIdentityInterface::KEY_ATTACHMENT_FILE_NAME => 'filename.pdf',
AttachmentIdentityInterface::KEY_ATTACHMENT_FILE_TYPE => 'pdf'
];
if ($attachments && is_array($attachments)) {
$attachments[] = $attachment;
$transportObject->setData(
AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA,
$attachments
);
} else {
$transportObject->setData(AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA, [
$attachment
]);
}
}
}