public void UpdateOrder(Order order)
 {
     if (order != null)
     {
         this.Order = order;
         this.OrderId = order.OrderId;
     }
 }
Example #2
0
        public static void CreateNewOrderNotificationToOrderAdminAndSave(this IGstoreDb db, StoreFrontConfiguration storeFrontConfig, UserProfile userProfile, Order order, UrlHelper urlHelper)
        {
            //user profile is null if user purchased as a guest
            if (storeFrontConfig == null)
            {
                throw new ArgumentNullException("storeFrontConfig");
            }
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (urlHelper == null)
            {
                throw new ArgumentNullException("urlHelper");
            }

            Uri currentUrl = urlHelper.RequestContext.HttpContext.Request.Url;
            string orderAdminUrl = urlHelper.Action("View", "Orders", new { area = "OrderAdmin", id = order.OrderNumber });
            string userViewOrderStatusUrl = urlHelper.Action("View", "OrderStatus", new { area = "", id = order.OrderNumber, Email = order.Email });

            UserProfile orderAdmin = storeFrontConfig.OrderAdmin;
            Notification notification = db.Notifications.Create();

            notification.StoreFront = storeFrontConfig.StoreFront;
            notification.StoreFront = storeFrontConfig.StoreFront;
            notification.ClientId = storeFrontConfig.ClientId;
            notification.Client = storeFrontConfig.Client;
            notification.From = "GStore Order Admin";
            notification.FromUserProfileId = orderAdmin.UserProfileId;
            notification.OrderId = order.OrderId;
            notification.ToUserProfileId = orderAdmin.UserProfileId;
            notification.To = orderAdmin.FullName;

            notification.Importance = "Normal";
            notification.Subject = "New Order #" + order.OrderNumber + " placed on " + currentUrl.Host + " at " + order.CreateDateTimeUtc.ToStoreDateTimeString(storeFrontConfig, storeFrontConfig.Client);

            notification.UrlHost = currentUrl.Host;
            if (!currentUrl.IsDefaultPort)
            {
                notification.UrlHost += ":" + currentUrl.Port;
            }
            notification.BaseUrl = urlHelper.Action("Details", "Notifications", new { area = "", id = "" });
            notification.Message = notification.Subject
                + "\n\nOrder Number: " + order.OrderNumber
                + "\nStore Front: " + storeFrontConfig.Name + " [" + storeFrontConfig.StoreFrontId + "]"
                + "\nClient: " + order.Client.Name + " [" + order.ClientId + "]"
                + "\nDate/Time: " + order.CreateDateTimeUtc.ToStoreDateTimeString(storeFrontConfig, storeFrontConfig.Client)
                + "\n"
                + "\nUser: "******"(guest)" : order.UserProfile.FullName + " <" + order.UserProfile.Email + "> [" + order.UserProfileId + "]")
                + "\nEmail: " + order.Email;

            notification.Message = notification.Message.ToHtmlLines();

            if (order.LoginOrGuestWebFormResponse != null)
            {
                //add custom fields from LoginOrGuestWebFormResponse
                notification.Message += order.LoginOrGuestWebFormResponse.ToSimpleTextForCheckout(true);
            }

            notification.Message += "\n"
                + "\nTax: $" + order.Tax.ToString("N2")
                + "\nShipping: $" + order.Shipping.ToString("N2")
                + "\nHandling: $" + order.Handling.ToString("N2")
                + "\nDiscount Code: " + order.DiscountCode.OrDefault("(none)")
                + "\nDiscount: " + order.Discount.ToStringDetails()
                + "\nOrder Discount: $" + order.OrderDiscount.ToString("N2")
                + "\nSubtotal: $" + order.Subtotal.ToString("N2")
                + "\nTotal: $" + order.Total.ToString("N2")
                + "\nPaid: $" + (order.Payments.Sum(p => p.AmountPaid).ToString("N2"));

            if (order.PaymentInfoWebFormResponse != null)
            {
                //add custom fields from PaymentInfoWebFormResponse
                notification.Message += order.PaymentInfoWebFormResponse.ToSimpleTextForCheckout(true);
            }
            notification.Message += "\n";
            notification.Message += "\nOrder Confirmed";
            if (order.ConfirmOrderWebFormResponse != null)
            {
                //add custom fields from LoginOrGuestWebFormResponse
                notification.Message += order.ConfirmOrderWebFormResponse.ToSimpleTextForCheckout(true);
            }

            notification.Message += "\n";
            if (order.DeliveryInfoShippingId.HasValue)
            {
                notification.Message += "\nShip To: " + order.DeliveryInfoShipping.ToOrderDetails(true) + "\n";
            }

            if (order.DeliveryInfoDigitalId.HasValue)
            {
                notification.Message += "\nDigital Delivery To: " + order.DeliveryInfoDigital.ToOrderDetails(true) + "\n";
            }

            notification.Message += "\nItem Count: " + order.ItemCount
                + "\nAll Items are Digital Download: " + (order.AllItemsAreDigitalDownload ? "Yes" : "No")
                + "\nItems to Ship: " + order.ShippingItemCount.ToString("N0")
                + "\nDigital Download Item Count: " + order.DigitalDownloadItemCount
                + "\n\nOrder Items: " + order.OrderItems.Count;

            int counter = 0;
            foreach (OrderItem item in order.OrderItems.OrderBy(oi => oi.OrderItemId))
            {
                counter++;
                notification.Message += "\nOrder Item " + counter + " " + item.ToOrderDetails();
            }

            notification.Message += "\n\nOrder Id: " + order.OrderId
                + "\nCart Id: " + order.OriginalCartId
                + "\nUser Agent: " + order.UserAgent
                + "\nSession Id: " + order.SessionId
                + "\nIP Address: " + order.IPAddress
                + "\nEntry Url: " + order.EntryUrl
                + "\nEntry Referrer: " + order.EntryReferrer
                + "\nEntry Raw Url: " + order.EntryRawUrl
                + "\nEntry Date Time: " + order.EntryDateTimeUtc.ToStoreDateTimeString(storeFrontConfig, storeFrontConfig.Client)
                + "\nDiscount Codes Attempted: " + order.DiscountCodesAttempted.OrDefault("(none)")
                + "\nDiscount Codes Failed: " + order.DiscountCodesFailed.OrDefault("(none)");

            notification.IsPending = false;
            notification.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            notification.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);

            List<NotificationLink> links = new List<NotificationLink>();

            NotificationLink link1 = db.NotificationLinks.Create();

            link1.SetDefaultsForNew(notification);
            link1.Order = 1;
            link1.LinkText = "Admin Order #" + order.OrderNumber;
            link1.Url = orderAdminUrl;
            link1.IsExternal = false;
            links.Add(link1);

            NotificationLink link2 = db.NotificationLinks.Create();
            link2.SetDefaultsForNew(notification);
            link2.Order = 2;
            link2.LinkText = "Order Status Link for User";
            link2.Url = userViewOrderStatusUrl;
            link2.IsExternal = false;
            links.Add(link2);

            notification.NotificationLinks = links;
            db.Notifications.Add(notification);

            db.SaveChanges();
        }