をオーバーライドします。
以前は、etc/di.xmlとmodel/Transport.phpの書き換えが成功しました。
<preference for="Magento\Framework\Mail\Transport" type="MyModul\MyPlugin\Model\Transport"/>
と
namespace MyModul\MyPlugin\Model;
class Transport extends \Zend_Mail_Transport_Sendmail implements \Magento\Framework\Mail\TransportInterface
{
protected $_message;
/**
* @param \Magento\Framework\Mail\MessageInterface $message
* @throws \Zend_Mail_Exception
*/
public function __construct(
\Magento\Framework\Mail\MessageInterface $message
)
{
if (!$message instanceof \Zend_Mail) {
throw new \InvalidArgumentException('The message should be an instance of \Zend_Mail');
}
parent::__construct('-f ' . '[email protected]');
$this->_message = $message;
}
/**
* Send a mail using this transport
*
* @return void
* @throws \Magento\Framework\Exception\MailException
*/
public function sendMessage()
{
try {
parent::send($this->_message);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
}
}
/**
* @inheritdoc
*/
public function getMessage()
{
return $this->_message;
}
/**
* Send mail using PHP native mail()
*
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception if parameters is set
* but not a string
* @throws Zend_Mail_Transport_Exception on mail() failure
*/
public function _sendMail()
{
/**
* revert changes from update to 2.1.7
*
* mailing was not working with Envelope >= 2.1.7
*/
if ($this->parameters === null) {
set_error_handler(array($this, '_handleMailErrors'));
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
restore_error_handler();
} else {
if(!is_string($this->parameters)) {
/**
* @see Zend_Mail_Transport_Exception
*
* Exception is thrown here because
* $parameters is a public property
*/
#require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception(
'Parameters were set but are not a string'
);
}
set_error_handler(array($this, '_handleMailErrors'));
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header,
$this->parameters);
restore_error_handler();
}
if ($this->_errstr !== null || !$result) {
/**
* @see Zend_Mail_Transport_Exception
*/
#require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);
}
}
}
しかし、今、私は一種の私は今行われることになっている方法であると思われ、プラグインを作成しようと試み
を失っています。
<type name="\Magento\Framework\Mail\Transport">
<plugin sortOrder="50" name="SendMailPlugin" type="MyModul\MyPlugin\Plugin\SendMailPlugin"/>
</type>
「TransportInterface」のオーバーライドについても読んでいますが、動作させることはできません。私はプラグインでコンストラクタを呼び出す必要があります。事前に
よろしくと感謝
UPDATE:
それが今再び取り組んでいます。問題は実際にはTransportInterfaceだけでした。私はクラスをオーバーライドするときに好みがインターフェイスを指す必要があり
<preference for="Magento\Framework\Mail\TransportInterface" type="MyModul\MyPlugin\Model\Transport" />
...私はすでにまたは多分それは「世代」キャッシュとは何かを持っていたことをしようと試みたと思いました。
私はまだ動作するようにプラグインのバージョンを取得しませんでした。私の最初の試みでは、プラグイン "after__construct"または "afterConstruct"でメソッドを呼び出す方法がわかりませんでした。また、parent :: contructを呼び出しています。
私はそれが最終的に動作するようになるなら私はそれを投稿します。
ご協力いただきありがとうございます。
UPDATE 2:contructのmethodesプラグインに設定することができないので
プラグイン溶液は、この場合には不可能イスト。 [OK]を
https://www.mageplaza.com/magento-2-module-development/magento-2-plugin-interceptor.html
これはmagento.stackexchange.comで行ってください。 – jmargolisvt