3

I added a "regular card number" attribute to the customer. It is essentially a unique code that when submitted by customer gives 20% discount. I would now like to send that code in an email to 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 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"}}
  • Which email template you want to send it? – Dhiren Vasoya Jan 11 '17 at 11:40
  • account_new_confirmed.html – Mateusz Serotiuk Jan 11 '17 at 11:42
  • @MateuszSerotiuk try to read my answer – LucScu Jul 29 '17 at 15:30
  • @MateuszSerotiuk, kindly post your email sending code too here. Need to make sure you are passing that variable as template variable. – Shashank Kumrawat Aug 10 '18 at 11:37
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" }}

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.