Skip to content

Commit

Permalink
[TASK] removed preferences, replaced with plugin, add date filter, fi…
Browse files Browse the repository at this point in the history
…xed little errors
  • Loading branch information
Derrick Heesbeen authored and Derrick Heesbeen committed Jan 11, 2018
1 parent 36b95ac commit 04a761e
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 292 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Forward/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
private function _construct()
protected function _construct()
{
parent::_construct();

Expand Down
6 changes: 4 additions & 2 deletions Block/Adminhtml/Forward/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ protected function _prepareLayout()

$emailCatcherId = $this->getRequest()->getParam('emailcatcher_id');

$emailCatcherIds = ($emailCatcherId) ? $emailCatcherId : implode(',', $this->getRequest()->getParam('selected'));
$selected = $this->getRequest()->getParam('selected');

$emailCatcherIds = ($emailCatcherId) ? $emailCatcherId : implode(',', $selected);

$form = $this->_formFactory->create();

Expand Down Expand Up @@ -41,7 +43,7 @@ protected function _prepareLayout()

$form->setUseContainer(true);
$form->setId('edit_form');
$form->setAction($this->getUrl('*/*/send', ['emailcatcher_id'=>$this->getRequest()->getParam('emailcatcher_id')]));
$form->setAction($this->getUrl('*/*/send', ['emailcatcher_id'=>$emailCatcherId]));
$form->setMethod('post');
$this->setForm($form);
}
Expand Down
Binary file added Docs/.DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Screenshots/email-catcher-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Screenshots/email-catcher-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Screenshots/emailcatcher-grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Screenshots/system-tools-emailcatcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 6 additions & 50 deletions Mail/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,35 @@
namespace Experius\EmailCatcher\Mail;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\MailException;
use Magento\Framework\Mail\MessageInterface;
use Magento\Framework\Mail\TransportInterface;
use Magento\Store\Model\ScopeInterface;

class Transport implements TransportInterface
class Transport extends \Magento\Email\Model\Transport
{

const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path';

const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email';

private $transport;

private $message;

private $scopeConfig;

private $emailCatcher;

public function __construct(
\Zend_Mail_Transport_Sendmail $transport,
MessageInterface $message,
ScopeConfigInterface $scopeConfig,
\Experius\EmailCatcher\Model\EmailcatcherFactory $emailCatcher
ScopeConfigInterface $scopeConfig
) {
if (!$message instanceof \Zend_Mail) {
throw new \InvalidArgumentException('The message should be an instance of \Zend_Mail');
}

$this->transport = $transport;
$this->message = $message;
$this->scopeConfig = $scopeConfig;
$this->emailCatcher = $emailCatcher;

parent::__construct($transport, $message, $scopeConfig);
}

public function sendMessage(\Magento\Framework\Mail\Message $message = null)
public function setMessage(\Magento\Framework\Mail\Message $message)
{

$message = (is_null($message)) ? $this->message : $message;

if ($this->scopeConfig->getValue('emailcatcher/general/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
$this->emailCatcher->create()->saveMessage($message);
}

if ($this->scopeConfig->getValue('system/smtp/disable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
return;
}


if ($this->scopeConfig->getValue('emailcatcher/general/smtp_disable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
return;
}

try {
$isSetReturnPath = $this->scopeConfig->getValue(
self::XML_PATH_SENDING_SET_RETURN_PATH,
ScopeInterface::SCOPE_STORE
);
$returnPathValue = $this->scopeConfig->getValue(
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
ScopeInterface::SCOPE_STORE
);

if ($isSetReturnPath == '1') {
$this->message->setReturnPath($message->getFrom());
} elseif ($isSetReturnPath == '2' && $returnPathValue !== null) {
$this->message->setReturnPath($returnPathValue);
}
$this->transport->send($message);
} catch (\Exception $e) {
throw new MailException(__($e->getMessage()), $e);
}
$this->message = $message;
}

public function getMessage()
Expand Down
3 changes: 2 additions & 1 deletion Model/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function sendMessage($emailCatcherId, $alternativeToAddress)
$message->setBodyHtml($emailCatcher->getBody());
$message->setSubject(mb_encode_mimeheader($emailCatcher->getSubject()));

$this->transport->sendMessage($message);
$this->transport->setMessage($message);
$this->transport->sendMessage();
}
}
23 changes: 23 additions & 0 deletions Plugin/Magento/Framework/Mail/TransportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@

namespace Experius\EmailCatcher\Plugin\Magento\Framework\Mail;

use Magento\Framework\App\Config\ScopeConfigInterface;

class TransportInterface
{

private $scopeConfig;

private $emailCatcher;

public function __construct(
ScopeConfigInterface $scopeConfig,
\Experius\EmailCatcher\Model\EmailcatcherFactory $emailCatcher
) {
$this->scopeConfig = $scopeConfig;
$this->emailCatcher = $emailCatcher;
}

public function aroundSendMessage(
\Magento\Framework\Mail\TransportInterface $subject,
\Closure $proceed
) {

if ($this->scopeConfig->getValue(
'emailcatcher/general/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
$this->emailCatcher->create()->saveMessage($subject->getMessage());
}

$proceed();
}
}
12 changes: 6 additions & 6 deletions Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,47 @@ public function install(
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
[],
'to'
'To Email Address'
);

$table_experius_emailcatcher->addColumn(
'from',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
[],
'from'
'From Email Address'
);

$table_experius_emailcatcher->addColumn(
'subject',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
[],
'subject'
'Subject'
);

$table_experius_emailcatcher->addColumn(
'body',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
[],
'body'
'Email Body'
);

$table_experius_emailcatcher->addColumn(
'created_at',
\Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
null,
[],
'created_at'
'Created At'
);

$table_experius_emailcatcher->addColumn(
'store_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
[],
'store_id'
'Store Id'
);

$setup->getConnection()->createTable($table_experius_emailcatcher);
Expand Down
60 changes: 0 additions & 60 deletions Test/Intergration/EmailCatcherTest.php

This file was deleted.

109 changes: 0 additions & 109 deletions Test/Mail/Template/TransportBuilder.php

This file was deleted.

Loading

0 comments on commit 04a761e

Please sign in to comment.