Esempio n. 1
0
        public string SendEmailTemplate(EmailTemplateNames templateName, Dictionary <string, string> tokens, string sendToEmail, DataModel.Store store)
        {
            //string storeEmail = storeContext.CurrentStore.GetSetting(StoreSettingNames.OrderCompletedEmailRecipient);
            string storeEmail           = store.GetSetting(StoreSettingNames.OrderCompletedEmailRecipient);
            string customerServiceEmail = store.GetSetting(StoreSettingNames.CustomerServiceEmailAddress);
            string hostEmail            = HostSettings.GetHostSetting("HostEmail");
            string from = !string.IsNullOrEmpty(customerServiceEmail) ? customerServiceEmail : hostEmail;

            vStoreEmailTemplate emailTemplate = store.GetStoreEmailTemplate(templateName);

            string subject = tokenizer.ReplaceTokensInString(HttpUtility.HtmlDecode(emailTemplate.SubjectTemplate), tokens);
            string body    = tokenizer.ReplaceTokensInString(HttpUtility.HtmlDecode(emailTemplate.BodyTemplate), tokens);

            body = InjectEmailCssIntoBody(body);

            return(SendEmail(from, sendToEmail, subject, body, true));
        }
Esempio n. 2
0
        internal Dictionary <string, string> GetOrderTokens(Order order, bool isEmail)
        {
            //StoreContext fakeContext = new StoreContext(HttpContext.Current.Request);
            //StoreUrls storeUrls = new StoreUrls(fakeContext);

            Dictionary <string, string> tokens = new Dictionary <string, string>();

            DataModel.Store store = order.UpToStoreByStoreId;

            tokens["store.name"] = store.Name;
            string customerServiceEmail = store.GetSetting(StoreSettingNames.CustomerServiceEmailAddress);

            if (!string.IsNullOrEmpty(customerServiceEmail))
            {
                tokens["store.contactemail"] = customerServiceEmail;
            }

            tokens["customer.userid"] = order.UserId.HasValue ? order.UserId.Value.ToString() : "anonymous";

            tokens["customer.firstname"] = order.CustomerFirstName;
            tokens["customer.lastname"]  = order.CustomerLastName;
            tokens["customer.email"]     = order.CustomerEmail;

            tokens["order.number"]          = order.OrderNumber;
            tokens["order.status"]          = order.OrderStatus.ToString();
            tokens["order.payment.status"]  = order.PaymentStatus.ToString();
            tokens["order.payment.summary"] = isEmail ? order.PaymentSummaryForEmail : order.PaymentSummary;

            tokens["order.date"]           = order.CreatedOn.Value.ToString();
            tokens["order.date.monthname"] = order.CreatedOn.Value.ToString("MMMM");
            tokens["order.date.day"]       = order.CreatedOn.Value.Day.ToString();
            tokens["order.date.year"]      = order.CreatedOn.Value.Year.ToString();

            tokens["order.subtotal"]     = storeContext.CurrentStore.FormatCurrency(order.SubTotal.GetValueOrDefault(0));
            tokens["order.shippingcost"] = storeContext.CurrentStore.FormatCurrency(order.ShippingAmount.GetValueOrDefault(0));
            tokens["order.discount"]     = storeContext.CurrentStore.FormatCurrency(order.DiscountAmount.GetValueOrDefault(0));
            tokens["order.couponcodes"]  = order.GetCoupons().ToDelimitedString(", ", t => t.CouponCode);
            tokens["order.tax"]          = storeContext.CurrentStore.FormatCurrency(order.TaxAmount.GetValueOrDefault(0));
            tokens["order.total"]        = storeContext.CurrentStore.FormatCurrency(order.Total.GetValueOrDefault(0));

            tokens["order.billing.address1"]    = order.BillAddress1;
            tokens["order.billing.address2"]    = order.BillAddress2;
            tokens["order.billing.city"]        = order.BillCity;
            tokens["order.billing.region"]      = order.BillRegion;
            tokens["order.billing.postalcode"]  = order.BillPostalCode;
            tokens["order.billing.countrycode"] = order.BillCountryCode;
            tokens["order.billing.telephone"]   = order.BillTelephone;

            tokens["order.billing.creditcardtype"]       = order.CreditCardType;
            tokens["order.billing.creditcardlast4"]      = order.CreditCardNumberLast4;
            tokens["order.billing.creditcardexpiration"] = order.CreditCardExpiration;

            tokens["order.shipping.recipientname"] = order.ShipRecipientName + (!string.IsNullOrEmpty(order.ShipRecipientBusinessName) ? "<br />" + order.ShipRecipientBusinessName : "");
            tokens["order.shipping.address1"]      = order.ShipAddress1;
            tokens["order.shipping.address2"]      = order.ShipAddress2;
            tokens["order.shipping.city"]          = order.ShipCity;
            tokens["order.shipping.region"]        = order.ShipRegion;
            tokens["order.shipping.postalcode"]    = order.ShipPostalCode;
            tokens["order.shipping.countrycode"]   = order.ShipCountryCode;
            tokens["order.shipping.telephone"]     = order.ShipTelephone;

            tokens["order.shipping.option"]         = order.ShippingServiceOption;
            tokens["order.shipping.cost"]           = order.ShippingAmount.GetValueOrDefault(0).ToString("C2");
            tokens["order.shipping.trackingnumber"] = order.TrackingNumbers.ToDelimitedString(", ");

            tokens["order.ordernotes"] = order.OrderNotes;

            List <OrderItem> orderItems = order.OrderItemCollectionByOrderId.ToList();

            if (orderItems.Count > 0)
            {
                tokens["order.itemsdelim"]        = GetOrderItemsDelimitedString(orderItems);
                tokens["order.itemstable"]        = GetOrderItemsTable(order);
                tokens["order.itemstablenoprice"] = GetOrderItemsTable(order, false);
                try
                {
                    tokens["order.itemsjson"] = GetOrderItemsJson(orderItems);
                }
                catch (Exception ex)
                {
                    Exceptions.LogException(ex);
                    if (tokens.ContainsKey("order.itemsjson"))
                    {
                        tokens.Remove("order.itemsjson");
                    }
                }
            }

            tokens["order.xml"] = XmlHelper.ToXml(order);

            return(tokens);
        }