protected void PopulateOrderLines(CustomerOrder customerOrder, dynamic emailModel) { emailModel.OrderLines = new List <ExpandoObject>(); foreach (OrderLine orderLine in customerOrder.OrderLines) { dynamic expandoObjects = new ExpandoObject(); expandoObjects.ProductNumber = orderLine.Product.ErpNumber; expandoObjects.Description = orderLine.Description; expandoObjects.QtyOrdered = decimal.Round(orderLine.QtyOrdered, 2); expandoObjects.QtyOrderedDisplay = expandoObjects.QtyOrdered.ToString("0.##"); expandoObjects.UnitNetPrice = orderLine.UnitNetPrice; expandoObjects.UnitNetPriceDisplay = this.CurrencyFormatProvider.GetString(orderLine.UnitNetPrice, customerOrder.Currency); expandoObjects.ExtendedUnitNetPrice = this.OrderLineUtilities.GetTotalNetPrice(orderLine); dynamic currency = expandoObjects; ICurrencyFormatProvider currencyFormatProvider = this.CurrencyFormatProvider; currency.ExtendedUnitNetPriceDisplay = currencyFormatProvider.GetString(expandoObjects.ExtendedUnitNetPrice, customerOrder.Currency); emailModel.OrderLines.Add(expandoObjects); } }
public override UpdateCartResult Execute(IUnitOfWork unitOfWork, UpdateCartParameter parameter, UpdateCartResult result) { if (!parameter.Status.EqualsIgnoreCase("AwaitingApproval")) { return(this.NextHandler.Execute(unitOfWork, parameter, result)); } CustomerOrder cart = result.GetCartResult.Cart; try { if (parameter.Status.EqualsIgnoreCase("AwaitingApproval") && result.GetCartResult.Cart != null) { CustomerOrder order = result.GetCartResult.Cart; string approverEmail = string.IsNullOrEmpty(order.ApproverUserProfile.Email) ? "" : order.ApproverUserProfile.Email; UserProfileDto userProfile = SiteContext.Current.UserProfileDto; dynamic emailModel = new ExpandoObject(); emailModel.OrderNumber = order.OrderNumber; emailModel.Name = order.PlacedByUserName; emailModel.Approver = order.ApproverUserProfile.FirstName; emailModel.Reason = order.ApproverMessage; emailModel.totalCost = order.ShippingCharges; DateTime date = order.OrderDate.Date; emailModel.OrderDate = date.ToShortDateString(); emailModel.CustomerPO = order.CustomerPO; emailModel.OrderLines = new List <ExpandoObject>(); foreach (OrderLine orderLine in order.OrderLines) { dynamic expandoObjects = new ExpandoObject(); expandoObjects.ProductNumber = orderLine.Product.ErpNumber; expandoObjects.Description = orderLine.Description; expandoObjects.QtyOrdered = decimal.Round(orderLine.QtyOrdered, 2); expandoObjects.QtyOrderedDisplay = expandoObjects.QtyOrdered.ToString("0.##"); expandoObjects.UnitNetPrice = orderLine.UnitNetPrice; expandoObjects.UnitNetPriceDisplay = this.CurrencyFormatProvider.GetString(orderLine.UnitNetPrice, order.Currency); expandoObjects.ExtendedUnitNetPrice = this.OrderLineUtilities.GetTotalNetPrice(orderLine); dynamic currency = expandoObjects; ICurrencyFormatProvider currencyFormatProvider = this.CurrencyFormatProvider; currency.ExtendedUnitNetPriceDisplay = currencyFormatProvider.GetString(expandoObjects.ExtendedUnitNetPrice, order.Currency); emailModel.OrderLines.Add(expandoObjects); } emailModel.Shipping = result.GetCartResult.ShippingAndHandling; emailModel.SubTotal = result.GetCartResult.OrderSubTotal; emailModel.Tax = result.GetCartResult.TotalTax; emailModel.OrderTotal = result.GetCartResult.OrderGrandTotal; emailModel.CustomerNumber = order.CustomerNumber; emailModel.BTCompanyName = order.BTCompanyName; emailModel.BTAddress1 = order.BTAddress1; emailModel.BTAddress2 = order.BTAddress2; emailModel.BTAddress3 = order.BTAddress3; emailModel.BTCity = order.BTCity; emailModel.BTState = order.BTState; emailModel.BTPostalCode = order.BTPostalCode; emailModel.STCompanyName = order.STCompanyName; emailModel.STAddress1 = order.STAddress1; emailModel.STAddress2 = order.STAddress2; emailModel.STAddress3 = order.STAddress3; emailModel.STCity = order.STCity; emailModel.STState = order.STState; emailModel.STPostalCode = order.STPostalCode; emailModel.BTDisplayName = order.BTFirstName + " " + order.BTLastName; emailModel.STDisplayName = order.STFirstName + " " + order.STLastName; emailModel.BTFirstName = order.BTFirstName; emailModel.BTLastName = order.BTLastName; emailModel.STFirstName = order.STFirstName; emailModel.STLastName = order.STLastName; if (order.ShipVia != null && order.ShipVia.Carrier != null) { emailModel.ShipMethod = order.ShipVia.Description; } else { emailModel.ShipMethod = string.Empty; } emailModel.Notes = order.Notes; emailModel.Handling = order.HandlingCharges; emailModel.HandlingDisplay = this.CurrencyFormatProvider.GetString(order.HandlingCharges, order.Currency); emailModel.OrderSubTotalDisplay = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderSubTotal, order.Currency); emailModel.OrderGrandTotalDisplay = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderGrandTotal, order.Currency); emailModel.OrderTotalDueDisplay = this.CurrencyFormatProvider.GetString(result.GetCartResult.OrderGrandTotal, order.Currency); emailModel.CustomerOrderTaxes = new List <ExpandoObject>(); foreach (CustomerOrderTax customerOrderTax in from o in order.CustomerOrderTaxes orderby o.SortOrder select o) { dynamic expandoObjects = new ExpandoObject(); expandoObjects.TaxCode = this.TranslationLocalizer.Value.TranslateLabel(customerOrderTax.TaxCode); expandoObjects.TaxDescription = this.TranslationLocalizer.Value.TranslateLabel(customerOrderTax.TaxDescription); expandoObjects.TaxRate = customerOrderTax.TaxRate; expandoObjects.TaxAmount = customerOrderTax.TaxAmount; expandoObjects.TaxAmountDisplay = this.CurrencyFormatProvider.GetString(customerOrderTax.TaxAmount, order.Currency); expandoObjects.SortOrder = customerOrderTax.SortOrder; emailModel.CustomerOrderTaxes.Add(expandoObjects); } emailModel.CreditCardWillBeCharged = result.GetCartResult.OrderGrandTotal; emailModel.TotalTaxDisplay = this.CurrencyFormatProvider.GetString(result.GetCartResult.TotalTax, order.Currency); var promotionProductDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionProductDiscountTotal(order); emailModel.PromotionProductDiscountTotal = promotionProductDiscountTotal; emailModel.PromotionProductDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionProductDiscountTotal, order.Currency); var promotionOrderDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionOrderDiscountTotal(order); emailModel.PromotionOrderDiscountTotal = promotionOrderDiscountTotal; emailModel.PromotionOrderDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionOrderDiscountTotal, order.Currency); var promotionShippingDiscountTotal = this.CustomerOrderUtilities.Value.GetPromotionShippingDiscountTotal(order); emailModel.PromotionShippingDiscountTotal = promotionShippingDiscountTotal; emailModel.PromotionShippingDiscountTotalDisplay = this.CurrencyFormatProvider.GetString(promotionShippingDiscountTotal, order.Currency); var giftCardTotal = this.CustomerOrderUtilities.Value.GetGiftCardTotal(order); emailModel.GiftCardTotal = giftCardTotal; emailModel.GiftCardTotalDisplay = this.CurrencyFormatProvider.GetString(giftCardTotal, order.Currency); //changes for BUSA-401 starts //emailModel.WebsiteUrl = order.Website.DomainName; //changes for BUSA-401 ends emailModel.WebsiteUrl = HttpContext.Current.Request.ActualUrl().GetLeftPart(UriPartial.Authority);//BUSA-552 : Incorrect URL in Order Approve email template var emailList = this.GetOrCreateEmailList("OrderApprove", "You have a new order to approve"); //this.EmailService.SendEmailList(emailList.Id, approverEmail, emailModel, string.Format("{0} {1}", emailList.Subject, order.OrderNumber), this.UnitOfWork); //BUSA-489 - commented the above line and added the below block //BUSA - 489 - start emailList = unitOfWork.GetRepository <EmailList>().GetTable().Expand((EmailList x) => x.EmailTemplate).FirstOrDefault((EmailList x) => x.Id == emailList.Id); if (emailList != null) { SendEmailParameter sendEmailParameter = new SendEmailParameter(); string htmlTemplate = GetHtmlTemplate(emailList); sendEmailParameter.Body = this.EmailService.ParseTemplate(htmlTemplate, emailModel); sendEmailParameter.Subject = string.Format("{0} {1}", emailList.Subject, order.OrderNumber); sendEmailParameter.ToAddresses.Add(approverEmail); sendEmailParameter.BccAddresses = new List <string>(); var emailCCAddresses = customSettings.EmailCCAddresses; if (!string.IsNullOrEmpty(emailCCAddresses)) { sendEmailParameter.CCAddresses.Add(emailCCAddresses); } string defaultEmailAddress = customSettings.DefaultEmailAddress; sendEmailParameter.FromAddress = (emailList.FromAddress.IsBlank() ? defaultEmailAddress : emailList.FromAddress); //Start BUSA - 685 :Create an ability to resend an email for Order Approve var emailCCAddressOfFrom = userProfile.Email; var emailCCAddressOfSupport = sendEmailParameter.FromAddress; if (!string.IsNullOrEmpty(emailCCAddressOfFrom)) { sendEmailParameter.CCAddresses.Add(emailCCAddressOfFrom); } if (!string.IsNullOrEmpty(emailCCAddressOfSupport)) { sendEmailParameter.CCAddresses.Add(emailCCAddressOfSupport); } //Start BUSA - 685 :Create an ability to resend an email for Order Approve sendEmailParameter.ReplyToAddresses = new List <string>(); sendEmailParameter.ExtendedProperties = new NameValueCollection(); SendEmail(sendEmailParameter, unitOfWork); } //BUSA - 489 - end } } catch (Exception ex) { LogHelper.For((object)this).Error((object)("There was a problem executing UpdateCartResult" + (object)ex.InnerException), ex.InnerException, (string)null, (object)null); throw ex; } return(NextHandler.Execute(unitOfWork, parameter, result)); }
protected void PopulateOrderEmailModel(dynamic emailModel, CustomerOrder customerOrder, IUnitOfWork unitOfWork) { string str; string str1; string str2; emailModel.OrderNumber = customerOrder.OrderNumber; DateTimeOffset orderDate = customerOrder.OrderDate.ToLocalTime(); //BUSA-477 Order Confirmation email contains wrong time emailModel.OrderDate = orderDate.ToString(CultureInfo.InvariantCulture); emailModel.CustomerPO = customerOrder.CustomerPO; dynamic obj = emailModel; str = (customerOrder.BTCompanyName.IsBlank() ? string.Concat(customerOrder.BTFirstName, " ", customerOrder.BTLastName).Trim() : customerOrder.BTCompanyName); obj.BTDisplayName = str; emailModel.CustomerNumber = customerOrder.CustomerNumber; if (customerOrder.ShipTo != null && !string.IsNullOrEmpty(customerOrder.ShipTo.CustomerSequence)) { // BUSA-472, 548, 508 : Duplicate Customers on Production Starts if (customerOrder.ShipTo.CustomerSequence.ToUpper().Contains("ISC")) { emailModel.CustomerShipToNumber = SiteContext.Current.ShipTo.CustomerSequence; } else { emailModel.CustomerShipToNumber = customerOrder.ShipTo.CustomerSequence; } // BUSA-472, 548, 508 : Duplicate Customers on Production Ends } else { emailModel.CustomerShipToNumber = string.Empty; } emailModel.BTAddress1 = customerOrder.BTAddress1; emailModel.BTAddress2 = customerOrder.BTAddress2; emailModel.BTAddress3 = customerOrder.BTAddress3; emailModel.BTCity = customerOrder.BTCity; emailModel.BTState = customerOrder.BTState; emailModel.BTZip = customerOrder.BTPostalCode; emailModel.BTPostalCode = customerOrder.BTPostalCode; emailModel.BTCountry = customerOrder.BTCountry; emailModel.BTCompany = customerOrder.BTCompanyName; emailModel.BTEmail = customerOrder.BTEmail; emailModel.BTPhone1 = customerOrder.BTPhone; dynamic obj1 = emailModel; str1 = (customerOrder.STCompanyName.IsBlank() ? string.Concat(customerOrder.STFirstName, " ", customerOrder.STLastName).Trim() : customerOrder.STCompanyName); obj1.STDisplayName = str1; emailModel.STAddress1 = customerOrder.STAddress1; emailModel.STAddress2 = customerOrder.STAddress2; emailModel.STAddress3 = customerOrder.STAddress3; emailModel.STCity = customerOrder.STCity; emailModel.STState = customerOrder.STState; emailModel.STZip = customerOrder.STPostalCode; emailModel.STPostalCode = customerOrder.STPostalCode; emailModel.STCountry = customerOrder.STCountry; emailModel.STCompany = customerOrder.STCompanyName; emailModel.STEmail = customerOrder.STEmail; emailModel.STPhone1 = customerOrder.STPhone; dynamic obj2 = emailModel; str2 = (customerOrder.ShipVia == null ? string.Empty : this.EntityTranslationService.Value.TranslateProperty <ShipVia>(customerOrder.ShipVia, (ShipVia o) => o.Description)); obj2.ShipMethod = str2; emailModel.Notes = customerOrder.Notes; ICurrencyFormatProvider value = this.CurrencyFormatProvider; Currency currency = null; if (customerOrder.CurrencyId.HasValue) { currency = unitOfWork.GetTypedRepository <ICurrencyRepository>().Get(customerOrder.CurrencyId.Value); } emailModel.PromotionProductDiscountTotal = this.CustomerOrderUtilities.GetPromotionProductDiscountTotal(customerOrder); emailModel.PromotionProductDiscountTotalDisplay = value.GetString(emailModel.PromotionProductDiscountTotal, currency); emailModel.PromotionOrderDiscountTotal = this.CustomerOrderUtilities.GetPromotionOrderDiscountTotal(customerOrder); emailModel.PromotionOrderDiscountTotalDisplay = value.GetString(emailModel.PromotionOrderDiscountTotal, currency); emailModel.PromotionShippingDiscountTotal = this.CustomerOrderUtilities.GetPromotionShippingDiscountTotal(customerOrder); emailModel.PromotionShippingDiscountTotalDisplay = value.GetString(emailModel.PromotionShippingDiscountTotal, currency); emailModel.FullShippingCharge = customerOrder.ShippingCharges; emailModel.FullShippingChargeDisplay = value.GetString(customerOrder.ShippingCharges, currency); emailModel.Handling = customerOrder.HandlingCharges; emailModel.HandlingDisplay = value.GetString(customerOrder.HandlingCharges, currency); emailModel.LocalTax = customerOrder.LocalTax; emailModel.LocalTaxDisplay = value.GetString(customerOrder.LocalTax, currency); emailModel.StateTax = customerOrder.StateTax; emailModel.StateTaxDisplay = value.GetString(customerOrder.StateTax, currency); emailModel.TotalTax = this.CustomerOrderUtilities.GetTotalTax(customerOrder); emailModel.TotalTaxDisplay = value.GetString(emailModel.TotalTax, currency); emailModel.CreditCardWillBeCharged = customerOrder.CreditCardTransactions.Any <CreditCardTransaction>(); emailModel.OrderSubTotal = this.CustomerOrderUtilities.GetOrderSubTotal(customerOrder); emailModel.OrderSubTotalDisplay = value.GetString(emailModel.OrderSubTotal, currency); emailModel.OrderSubTotalWithOutProductDiscounts = this.CustomerOrderUtilities.GetPromotionProductDiscountTotal(customerOrder) + this.CustomerOrderUtilities.GetOrderSubTotal(customerOrder); emailModel.OrderSubTotalWithOutProductDiscountsDisplay = value.GetString(emailModel.OrderSubTotalWithOutProductDiscounts, currency); emailModel.OrderGrandTotal = this.CustomerOrderUtilities.GetOrderTotal(customerOrder); emailModel.OrderGrandTotalDisplay = value.GetString(emailModel.OrderGrandTotal, currency); emailModel.GiftCardTotal = this.CustomerOrderUtilities.GetGiftCardTotal(customerOrder); emailModel.GiftCardTotalDisplay = value.GetString(emailModel.GiftCardTotal, currency); emailModel.OrderTotalDue = this.GetOrderTotalDue(customerOrder); emailModel.OrderTotalDueDisplay = value.GetString(emailModel.OrderTotalDue, currency); //emailModel.CustomerOrderTaxes = this.PopulateCustomerOrderTaxEmailModel(customerOrder, unitOfWork); kkk this.PopulateCustomerOrderTaxes(customerOrder, emailModel); //emailModel.OrderLines = this.PopulateOrderLineEmailModel(customerOrder, unitOfWork); kkk this.PopulateOrderLines(customerOrder, emailModel); if (customerOrder.CustomProperties.Where(x => x.Name == "subscriptionFrequencyOpted").Count() > 0) { var frequency = customerOrder.CustomProperties.FirstOrDefault(x => x.Name == "subscriptionFrequencyOpted").Value; if (!string.IsNullOrEmpty(frequency)) { emailModel.SubscriptionFrequency = int.Parse(frequency) / 7; } } }