public void Can_save_and_load_orderNote() { var on = new OrderNote() { Order = GetTestOrder(), Note = "Note1", DisplayToCustomer= true, CreatedOnUtc = new DateTime(2010, 01, 01), }; var fromDb = SaveAndLoadEntity(on); fromDb.ShouldNotBeNull(); fromDb.Note.ShouldEqual("Note1"); fromDb.DisplayToCustomer.ShouldEqual(true); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01)); fromDb.Order.ShouldNotBeNull(); }
/// <summary> /// Deletes an order note /// </summary> /// <param name="orderNote">The order note</param> public virtual void DeleteOrderNote(OrderNote orderNote) { if (orderNote == null) throw new ArgumentNullException("orderNote"); int orderId = orderNote.OrderId; _orderNoteRepository.Delete(orderNote); //event notifications _eventPublisher.EntityDeleted(orderNote); var order = GetOrderById(orderId); _eventPublisher.PublishOrderUpdated(order); }
public virtual void AddOrderNoteTokens(IList<Token> tokens, OrderNote orderNote) { tokens.Add(new Token("Order.NewNoteText", orderNote.FormatOrderNoteText(), true)); //event notification _eventPublisher.EntityTokensAdded(orderNote, tokens); }
/// <summary> /// Sends a new order note added notification to a customer /// </summary> /// <param name="orderNote">Order note</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public virtual int SendNewOrderNoteAddedCustomerNotification(OrderNote orderNote, int languageId) { if (orderNote == null) throw new ArgumentNullException("orderNote"); var order = orderNote.Order; var store = _storeService.GetStoreById(order.StoreId) ?? _storeContext.CurrentStore; languageId = EnsureLanguageIsActive(languageId, store.Id); var messageTemplate = GetLocalizedActiveMessageTemplate("Customer.NewOrderNote", languageId, store.Id); if (messageTemplate == null) return 0; //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store); _messageTokenProvider.AddOrderNoteTokens(tokens, orderNote); _messageTokenProvider.AddOrderTokens(tokens, orderNote.Order, languageId); _messageTokenProvider.AddCustomerTokens(tokens, orderNote.Order.Customer); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); var toEmail = order.BillingAddress.Email; var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName); return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName); }
public ActionResult OrderNoteAdd(int orderId, bool displayToCustomer, string message) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(orderId); if (order == null) return Json(new { Result = false }, JsonRequestBehavior.AllowGet); var orderNote = new OrderNote() { DisplayToCustomer = displayToCustomer, Note = message, CreatedOnUtc = DateTime.UtcNow, }; order.OrderNotes.Add(orderNote); _orderService.UpdateOrder(order); //new order notification if (displayToCustomer) { //email _workflowMessageService.SendNewOrderNoteAddedCustomerNotification( orderNote, _workContext.WorkingLanguage.Id); } return Json(new { Result = true }, JsonRequestBehavior.AllowGet); }
/// <summary> /// Deletes an order note /// </summary> /// <param name="orderNote">The order note</param> public virtual void DeleteOrderNote(OrderNote orderNote) { if (orderNote == null) throw new ArgumentNullException("orderNote"); _orderNoteRepository.Delete(orderNote); //event notification _eventPublisher.EntityDeleted(orderNote); }
public void AddCustomerOrderNoteLoop(AmazonPayActionState state) { try { var sleepMillSec = 4000; var loopMillSec = 40000; var startTime = DateTime.Now.TimeOfDay; for (int i = 0; i < 99 && (DateTime.Now.TimeOfDay.Milliseconds - startTime.Milliseconds) <= loopMillSec; ++i) { var order = _orderService.GetOrderByGuid(state.OrderGuid); if (order != null) { var sb = new StringBuilder(T("Plugins.Payments.AmazonPay.AuthorizationHardDeclineMessage")); if (state.Errors != null) { foreach (var error in state.Errors) sb.AppendFormat("<p>{0}</p>", error); } var orderNote = new OrderNote() { DisplayToCustomer = true, Note = sb.ToString(), CreatedOnUtc = DateTime.UtcNow, }; order.OrderNotes.Add(orderNote); _orderService.UpdateOrder(order); _workflowMessageService.SendNewOrderNoteAddedCustomerNotification(orderNote, _services.WorkContext.WorkingLanguage.Id); break; } Thread.Sleep(sleepMillSec); } } catch (Exception exc) { LogError(exc); } }