/// <summary> /// Replaces a message template tokens /// </summary> /// <param name="returnRequest">Return request</param> /// <param name="template">Template</param> /// <returns>New template</returns> private string ReplaceMessageTemplateTokens(ReturnRequest returnRequest, string template) { var tokens = new NameValueCollection(); tokens.Add("Store.Name", IoC.Resolve<ISettingManager>().StoreName); tokens.Add("Store.URL", IoC.Resolve<ISettingManager>().StoreUrl); tokens.Add("Store.Email", this.DefaultEmailAccount.Email); tokens.Add("Customer.Email", HttpUtility.HtmlEncode(returnRequest.Customer.Email)); tokens.Add("Customer.FullName", HttpUtility.HtmlEncode(returnRequest.Customer.FullName)); tokens.Add("ReturnRequest.ID", returnRequest.ReturnRequestId.ToString()); tokens.Add("ReturnRequest.Product.Quantity", returnRequest.Quantity.ToString()); tokens.Add("ReturnRequest.Product.Name", HttpUtility.HtmlEncode(returnRequest.OrderProductVariant.ProductVariant.FullProductName)); tokens.Add("ReturnRequest.Reason", HttpUtility.HtmlEncode(returnRequest.ReasonForReturn)); tokens.Add("ReturnRequest.RequestedAction", HttpUtility.HtmlEncode(returnRequest.RequestedAction)); tokens.Add("ReturnRequest.CustomerComment", returnRequest.FormatReturnRequestCommentsText()); foreach (string token in tokens.Keys) { template = Replace(template, String.Format(@"%{0}%", token), tokens[token]); } return template; }
/// <summary> /// Sends 'Return Request status changed' message to a customer /// </summary> /// <param name="returnRequest">Return request</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public int SendReturnRequestStatusChangedCustomerNotification(ReturnRequest returnRequest, int languageId) { if (returnRequest == null) throw new ArgumentNullException("returnRequest"); if (returnRequest.Customer == null) throw new NopException("Customer of return request could not be loaded"); string templateName = "ReturnRequestStatusChanged.CustomerNotification"; var localizedMessageTemplate = this.GetLocalizedMessageTemplate(templateName, languageId); if (localizedMessageTemplate == null || !localizedMessageTemplate.IsActive) return 0; var emailAccount = localizedMessageTemplate.EmailAccount; string subject = ReplaceMessageTemplateTokens(returnRequest, localizedMessageTemplate.Subject); string body = ReplaceMessageTemplateTokens(returnRequest, localizedMessageTemplate.Body); string bcc = localizedMessageTemplate.BccEmailAddresses; var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName); var to = new MailAddress(returnRequest.Customer.Email, returnRequest.Customer.FullName); var queuedEmail = InsertQueuedEmail(5, from, to, string.Empty, bcc, subject, body, DateTime.UtcNow, 0, null, emailAccount.EmailAccountId); return queuedEmail.QueuedEmailId; }
/// <summary> /// Inserts a return request /// </summary> /// <param name="returnRequest">Return request</param> /// <param name="notifyStoreOwner">A value indicating whether to notify about new return request</param> public void InsertReturnRequest(ReturnRequest returnRequest, bool notifyStoreOwner) { if (returnRequest == null) throw new ArgumentNullException("returnRequest"); returnRequest.ReasonForReturn = CommonHelper.EnsureNotNull(returnRequest.ReasonForReturn); returnRequest.ReasonForReturn = CommonHelper.EnsureMaximumLength(returnRequest.ReasonForReturn, 400); returnRequest.RequestedAction = CommonHelper.EnsureNotNull(returnRequest.RequestedAction); returnRequest.RequestedAction = CommonHelper.EnsureMaximumLength(returnRequest.RequestedAction, 400); returnRequest.CustomerComments = CommonHelper.EnsureNotNull(returnRequest.CustomerComments); returnRequest.StaffNotes = CommonHelper.EnsureNotNull(returnRequest.StaffNotes); _context.ReturnRequests.AddObject(returnRequest); _context.SaveChanges(); if (notifyStoreOwner) { IoC.Resolve<IMessageService>().SendNewReturnRequestStoreOwnerNotification(returnRequest, IoC.Resolve<ILocalizationManager>().DefaultAdminLanguage.LanguageId); } }
/// <summary> /// Updates the return request /// </summary> /// <param name="returnRequest">Return request</param> public void UpdateReturnRequest(ReturnRequest returnRequest) { if (returnRequest == null) throw new ArgumentNullException("returnRequest"); returnRequest.ReasonForReturn = CommonHelper.EnsureNotNull(returnRequest.ReasonForReturn); returnRequest.ReasonForReturn = CommonHelper.EnsureMaximumLength(returnRequest.ReasonForReturn, 400); returnRequest.RequestedAction = CommonHelper.EnsureNotNull(returnRequest.RequestedAction); returnRequest.RequestedAction = CommonHelper.EnsureMaximumLength(returnRequest.RequestedAction, 400); returnRequest.CustomerComments = CommonHelper.EnsureNotNull(returnRequest.CustomerComments); returnRequest.StaffNotes = CommonHelper.EnsureNotNull(returnRequest.StaffNotes); if (!_context.IsAttached(returnRequest)) _context.ReturnRequests.Attach(returnRequest); _context.SaveChanges(); }
protected void btnSubmit_Click(object sender, EventArgs e) { int count = 0; foreach (GridViewRow row in gvOrderProductVariants.Rows) { HiddenField hfOpvId = row.FindControl("hfOpvId") as HiddenField; DropDownList ddlQuantity = row.FindControl("ddlQuantity") as DropDownList; if (hfOpvId != null && ddlQuantity != null) { int quantity = Convert.ToInt32(ddlQuantity.SelectedValue); if (quantity > 0) { int opvId = Convert.ToInt32(hfOpvId.Value); var opv = this.OrderService.GetOrderProductVariantById(opvId); if (opv != null) { if (opv.Order.CustomerId == NopContext.Current.User.CustomerId) { DateTime dtNow = DateTime.UtcNow; var rr = new ReturnRequest() { OrderProductVariantId = opv.OrderProductVariantId, Quantity = quantity, CustomerId = NopContext.Current.User.CustomerId, ReasonForReturn = ddlReturnReason.SelectedValue, RequestedAction = ddlReturnAction.SelectedValue, CustomerComments = txtComments.Text, StaffNotes = string.Empty, ReturnStatusId = (int)ReturnStatusEnum.Pending, CreatedOn = dtNow, UpdatedOn = dtNow }; this.OrderService.InsertReturnRequest(rr, true); count++; } } } } } phInput.Visible = false; phResult.Visible = true; if (count > 0) { lResults.Text = GetLocaleResourceString("ReturnItems.Submitted"); } else { lResults.Text = GetLocaleResourceString("ReturnItems.NoItems"); } }