We have a section of our confirmation email that shows which student (recipient) is registered for each class. For some reason it is returning the same student for every class registered in the order. So, if siblings are registered in the same order it is showing that it all belongs to one of them. The recipient is correct in the order, just an issue of the confirmation email showing the wrong name. I must have missed testing this scenario when we were implementing this.
Any of you able to spot what might be causing the problem? I've highlighted the bit that is displaying the wrong name.
Thanks for any help you can offer!
@if(hasProducts)
{ var perfs = (Model.OrderProductView.Products).Where(x => x.ProductClass.Description == "Performance");
if (perfs != null && perfs.Count() > 0) { <h2>Drama School Registration:</h2> foreach (var product in perfs) { var performance = product.Performance.LineItem.Performance; var urlInventory = "TXN/Performances/" + performance.Id; var inventoryObject = Model.RestClient.AtUrl(urlInventory).Get<Performance>().ResponseObject;
if(!performance.Description.Contains("T-Shirt") && !performance.Description.Contains("Hoodie")) { <b> @recipient has been registered for: </b> <br> @inventoryObject.Text1 <br> @inventoryObject.Text2 <br> @inventoryObject.Text3 <br> @inventoryObject.Text4 <br><br> } } } }
Thanks all for your responses. I've pasted the top section of the template below. The only other area of the template where recipient is mentioned is the section I originally posted. Yes, student=recipient. @using Tessitura.Service.Client.CRM;@using Tessitura.Service.Client.Txn;@{ var hasConstituent = Model.OrderProductView.Constituent != null; var hasAddress = Model.Address != null; var hasElectronicAddress = Model.ElectronicAddress != null; var hasBooking = Model.Booking != null; var isInFriendsCircle = false; var hasState = hasAddress && Model.Address.State != null; var hasProducts = Model.OrderProductView.Products != null && Model.OrderProductView.Products.Count > 0; var regnum = 0; var hasPaymentPlan = Model.OrderProductView.PaymentPlans != null; var objectRecipient = hasProducts ? Model.OrderProductView.Products.FirstOrDefault() : null; var objectPerformance = (objectRecipient != null) ? objectRecipient.Performance : null; var objectSubLineItem = objectPerformance != null ? objectPerformance.LineItem.SubLineItems.FirstOrDefault() : null; var recipient = objectSubLineItem != null ? (objectSubLineItem.Recipient != null ? (objectSubLineItem.Recipient.DisplayName != null ? objectSubLineItem.Recipient.DisplayName : string.Empty): string.Empty) : string.Empty;
}
Hi Kanani,
Your objectRecipient (which is a product --OrderProductViewProduct) is only fetching the first product with the FirstorDefault() method.
Likewise with the objectSubLineItem, so in effect there are no SubLineItems to loop over.
Like Gawain Lavers mentioned, you can define the recipient inside the subline loop, along the lines of...
foreach (var product in perfs) { var performance = product.Performance.LineItem.Performance; var objectSLI = performance.LineItem.SubLineItems; foreach (var sli in objectSLI) { var recipient = sli.Recipient.DisplayName; <p>@recipient</p> } }
-Ryan
Thanks, Ryan
apologies... i was moving variables around. that first performance var would be product.Performance;