Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bex 444 posts 555 karma points
    Sep 27, 2016 @ 15:27
    Bex
    0

    Discount code in order confirmation email

    Hi

    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)

    Thanks for any help

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 27, 2016 @ 17:03
    Rusty Swayne
    0

    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.

  • Bex 444 posts 555 karma points
    Sep 28, 2016 @ 14:21
    Bex
    0

    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:

    {{IterationStart[Invoice.Discounts]}}
              <table>
                     <tr> 
                        <td>SKU</td>
                        <td><strong>{{Discount.Code}}</strong></td>
                      </tr>
                      <tr>
                        <td></td>
                        <td><strong>{{Discount.Name}}</strong></td>
                      </tr>
                      <tr>
                        <td >Total Discount</td>
                        <td><strong>-{{Discount.TotalDiscount}}</strong></td>
                      </tr>
                    </table>
    
                {{IterationEnd[Invoice.Discounts]}}
    

    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?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 28, 2016 @ 20:25
    Rusty Swayne
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft