4

I added a "regular card number" attribute to the customer. It is essentially a unique code that when submitted by the customer gives a 20% discount. I would now like to send that code in an email to the customer, but Magento doesn't seem to add it.

<li>{{trans "Regular card number: %card_number" card_number=$customer.getCardNumber()}} {{var customer.custom('card_number')}}</li>

Any ideas on how to add this variable to an email template?

Thank you!


Full code of my template:

<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<!--@subject {{trans "Welcome to %store_name" store_name=$store.getFrontendName()}} @-->
<!--@vars {
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
"var customer.email":"Customer Email",
"var customer.name":"Customer Name",
} @-->
{{template config_path="design/email/header_template"}}

<p class="greeting">{{trans "%name," name=$customer.name}}</p>
<p>{{trans "Thank you for confirming your %store_name account." store_name=$store.getFrontendName()}}</p>
<p>
    {{trans
        'To sign in to our site, use these credentials during checkout or on the <a href="%customer_url">My Account</a> page:'

        customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
    |raw}}
</p>
<ul>
    <li><strong>{{trans "Email:"}}</strong> {{var customer.email}}</li>
    <li><strong>{{trans "Password:"}}</strong> <em>{{trans "Password you set when creating account"}}</em></li>
    <li>{{trans "Regular card number: %card_number" card_number=$customer.getCardNumber()}} {{var customer.custom('card_number')}}</li>
</ul>
<p>
    {{trans
        'Forgot your account password? Click <a href="%reset_url">here</a> to reset it.'

        reset_url="$this.getUrl($store,'customer/account/createPassword/',[_query:[id:$customer.id,token:$customer.rp_token],_nosid:1])"
    |raw}}
</p>
<p>{{trans "When you sign in to your account, you will be able to:"}}</p>
<ul>
    <li>{{trans "Proceed through checkout faster"}}</li>/
    <li>{{trans "Check the status of orders"}}</li>
    <li>{{trans "View past orders"}}</li>
    <li>{{trans "Store alternative addresses (for shipping to multiple family members and friends)"}}</li>
</ul>

{{template config_path="design/email/footer_template"}}
4
  • Which email template you want to send it? Commented Jan 11, 2017 at 11:40
  • account_new_confirmed.html Commented Jan 11, 2017 at 11:42
  • @MateuszSerotiuk try to read my answer
    – LucScu
    Commented Jul 29, 2017 at 15:30
  • @MateuszSerotiuk, kindly post your email sending code too here. Need to make sure you are passing that variable as template variable. Commented Aug 10, 2018 at 11:37

3 Answers 3

1

First, i think you have to check if in Magento\Customer\Model\EmailNotification in the method newAccount() the variable $customerEmailData contains your card_number values.

Then if it is present you can retrieve it in template with

<p><strong>{{trans "Regular card number:"}}</strong> {{var customer.card_number}}</p>

Instead if it is not present you have to add it to template params (see the sendEmailTemplate() method).

Now the newAccount() method hasn't a dispatched event, so you can't use event/observer, you can try with a plugin, even if i think that in this case the safest ways is to override the class and the method with a custom class.

0

Use var at place of trans {{var "Regular card number: %card_number" }}

1
  • 1
    Hmm... This doesn't seem to work Commented Jan 11, 2017 at 12:13
0

My sales_order table had new fields like delivery_date and I wanted to display it in my new order template. I added like this.

{{trans 'Your order is on its way in slot %delivery_date' delivery_date=$order.delivery_date |raw }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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