3

Transactional email variables not passing to template. I'm defining the email variables and sending the email as such.

class Sendemail
{

   /**
     * @var  \Magento\Framework\Mail\Template\TransportBuilder
     */
    private $_transportBuilder;

  public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder){

    $this->_transportBuilder = $transportBuilder;
  }

  public function sendEmail($sender, $recipient, $template, $store)
  {



    $retrievalcode = "somecustomcode";    
    $vars = Array('retrieval_code' => $retrievalcode);

     $transport = $this->_transportBuilder->setTemplateIdentifier($template)
            ->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $store])
            ->setTemplateVars($vars)
            ->setFrom($sender)
            ->addTo($recipient)
            ->getTransport();
        $transport->sendMessage();
  }

}

The email is sending but it not including the defined template variable. Any suggestions would be appreciated.The variable is being call in the transactional email template as:

{{var retrieval_code}}
4
class Sendemail
{
    /**
     * @var  \Magento\Framework\Mail\Template\TransportBuilder
     */
    private $_transportBuilder;

    public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder){

        $this->_transportBuilder = $transportBuilder;
    }

    public function sendEmail($sender, $recipient, $template, $storeId)
    {
        $parseDataVars = new \Magento\Framework\DataObject();

        $retrievalcode = "somecustomcode";
        $parseDataVars->setData(array('retrieval_code' => $retrievalcode));

        $transport = $this->_transportBuilder->setTemplateIdentifier($template)
            ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
            ->setTemplateVars(array('data' => $parseDataVars))
            ->setFrom($sender)
            ->addTo($recipient)
            ->getTransport();
        $transport->sendMessage();
    }
}
| improve this answer | |
  • 1
    then reference var in template with {{var data.retrieval_code}} – Xenocide8998 Nov 2 '16 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.