I have the following in my order confirmation email:
Discounts
-{{TotalDiscountPrice}}
But I would like to also show the actual discount code used by the customer.
Is there a way of doing this? I cannot see this option in the documentation.
(bearing in mind we're on merchello v1.11.0 if it makes a difference)
Yep, being on 1.11.0 makes a difference =) The Razor view would be much easier.
The SKU field of the discount line item is generally the discount code - can you use that? Otherwise adding a pattern is possible but takes a bit of work.
FYI The pattern format based emails have been obsoleted in favor of the razor based templates.
Unfortunately we are stuck on v.1.11.0 for now as a previous developer has integrated it into a project and bolted on lots of bits we're still finding.
I've had a look whats available and it appears that you can't get at the actual discount code so I am trying to add in s bit of new functionality.
I have delved into the core code and added the following into lineItemExtensions (Kind of of following the same as the line items)
Internal static IEnumerable<IReplaceablePattern> DiscountItemReplaceablePatterns(this ILineItemContainer container, string currencySymbol)
{
var patterns = new List<IReplaceablePattern>();
var token = "Invoice.Discounts";
var iterateItems =
container.Items.Where(
x => (x.LineItemType == LineItemType.Discount)).ToArray();
// TODO localization needed on pricing and datetime
for (var i = 0; i < iterateItems.Count(); i++)
{
var code = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Code", i), string.Format("{0}Discount.Code.{1}{2}", "{{", i, "}}"), iterateItems[i].LineItemType == LineItemType.Shipping ? string.Empty : iterateItems[i].Sku);
var name = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Name", i), string.Format("{0}Discount.Name.{1}{2}", "{{", i, "}}"), iterateItems[i].Name);
var totalDiscount = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "TotalDiscount", i), string.Format("{0}Discount.TotalDiscount.{1}{2}", "{{", i, "}}"), iterateItems[i].TotalPrice.FormatAsPrice(currencySymbol));
patterns.Add(code);
patterns.Add(name);
patterns.Add(totalDiscount);
}
return patterns.Where(x => x != null);
}
and then added a call to this in ReplaceablePatterns in InvoiceExtensions.cs
I can't work out what I need to do next though to tell it to do the replacing? Am I going the right way?
Discount code in order confirmation email
Hi
I have the following in my order confirmation email:
But I would like to also show the actual discount code used by the customer. Is there a way of doing this? I cannot see this option in the documentation.
(bearing in mind we're on merchello v1.11.0 if it makes a difference)
Thanks for any help
Hey Bex
Yep, being on 1.11.0 makes a difference =) The Razor view would be much easier.
The SKU field of the discount line item is generally the discount code - can you use that? Otherwise adding a pattern is possible but takes a bit of work.
FYI The pattern format based emails have been obsoleted in favor of the razor based templates.
Hi Rusty!
Thanks for your reply.
Unfortunately we are stuck on v.1.11.0 for now as a previous developer has integrated it into a project and bolted on lots of bits we're still finding.
I've had a look whats available and it appears that you can't get at the actual discount code so I am trying to add in s bit of new functionality.
I want something like this in my email template:
I have delved into the core code and added the following into lineItemExtensions (Kind of of following the same as the line items)
and then added a call to this in ReplaceablePatterns in InvoiceExtensions.cs
I can't work out what I need to do next though to tell it to do the replacing? Am I going the right way?
Hey Bex
It's was a pretty clunky mechanic, but there is not much to it. Basically we built up a list of pairs. For the invoice we used this extension:
https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Models/InvoiceExtensions.cs#L173
For the line items - we used:
https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Models/LineItemExtensions.cs#L461
If your going to create your own 1.11."1" version, you might have a look at the line item extension.
is working on a reply...