เทมเพลตอีเมล Magento 2 วิธีเพิ่ม Controller Path
Sep 19 2020
ฉันต้องการเพิ่มเส้นทางตัวควบคุมในเทมเพลตอีเมลฉันได้สร้างเทมเพลตอีเมลแบบกำหนดเองโดยใช้โปรแกรม
นี่คือรหัสของฉัน: -
{{template config_path="design/email/header_template"}}
<table>
<tr class="custom-gdpr">
<p><strong>Hello {{var name}} , </strong></p>
<p>You Are Confirom Delete Your Account in Our Store. </p>
<p>If {{trans '<a href="Here I want to controller URL">Yes</a>'|row}} Or {{trans '<a href="Here I want to controller URL">No</a>'|row}}</p>
<strong>Thank you</strong>
</tr>
</table>
{{template config_path="design/email/footer_template"}}
ฉันต้องการเพิ่มลิงค์ต่อไปนี้ For Example:-
xyz.com/routername/controllername/action/customerid/encryptedid..
โปรดแนะนำฉันวิธีเพิ่ม URL แบบไดนามิก
THANKS.
คำตอบ
1 SohelRana Sep 19 2020 at 11:28
ลองทำตามวิธีต่อไปนี้:
use Magento\Framework\DataObject;
ตอนนี้เมื่อคุณส่งอีเมลธุรกรรมคุณต้องส่งค่าเป็น DataObject Object เช่น
'data' => new DataObject($post)
โดยที่ $ post คืออาร์เรย์
ตั้งค่าตัวแปรเช่น:
->setTemplateVars($variables)
ตรวจสอบโมดูล Magento_Contact เป็นตัวอย่าง โดยเฉพาะคลาสต่อไปนี้:
1. vendor / magento / module-contact / Controller / Index / Post.php
private function sendEmail($post)
{
$this->mail->send( $post['email'],
['data' => new DataObject($post)]
);
}
2. vendor / magento / module-contact / Model / Mail.php
public function send($replyTo, array $variables) { /** @see \Magento\Contact\Controller\Index\Post::validatedParams() */ $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
$this->inlineTranslation->suspend(); try { $transport = $this->transportBuilder ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId() ] ) ->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender()) ->addTo($this->contactsConfig->emailRecipient())
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage(); } finally { $this->inlineTranslation->resume();
}
}
3. vendor / magento / module-contact / view / frontend / email / submit_form.html
{{var data.email}}