public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; //(GMT+02:00) Minsk; var customer = new Customer() { Id = 10 }; _genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer")) .Return(new List <GenericAttribute>() { new GenericAttribute() { StoreId = 0, EntityId = customer.Id, Key = SystemCustomerAttributeNames.TimeZoneId, KeyGroup = "Customer", Value = "Russian Standard Time" //(GMT+03:00) Moscow, St. Petersburg, Volgograd } }); var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual("Russian Standard Time"); }
public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; // (GMT+02:00) Minsk; var customer = _customerService.GetCustomerById(1); var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual("Russian Standard Time"); }
public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; //(GMT+02:00) Minsk; var customer = new Customer() { TimeZoneId = "Russian Standard Time" //(GMT+03:00) Moscow, St. Petersburg, Volgograd }; var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual("Russian Standard Time"); }
public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = gmtPlus2TimeZoneId; //(GMT+02:00) Minsk; var customer = new Customer { Id = 10 }; _genericAttributeService.Setup(x => x.GetAttribute <string>(customer, NopCustomerDefaults.TimeZoneIdAttribute, 0)) .Returns(gmtPlus3TimeZoneId); //(GMT+03:00) Moscow, St. Petersburg, Volgograd var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual(gmtPlus3TimeZoneId); }
public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = _gmtPlus2MinskTimeZoneId; var customer = new Customer { Id = 10 }; _genericAttributeService.Setup(x => x.GetAttribute <string>(customer, NopCustomerDefaults.TimeZoneIdAttribute, 0)) .Returns(_gmtPlus3MoscowTimeZoneId); var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual(_gmtPlus3MoscowTimeZoneId); }
public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; // (GMT+02:00) Minsk; var customer = new Customer { Id = 10 }; _genericAttributeService .Expect(x => x.GetAttribute <string>(nameof(Customer), customer.Id, SystemCustomerAttributeNames.TimeZoneId, 0)) .Return("Russian Standard Time"); // (GMT+03:00) Moscow, St. Petersburg, Volgograd var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull(); timeZone.Id.ShouldEqual("Russian Standard Time"); }
public virtual void AddOrderTokens(IList <Token> tokens, Order order, int languageId) { tokens.Add(new Token("Order.OrderNumber", order.Id.ToString())); tokens.Add(new Token("Order.CustomerFullName", string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName))); tokens.Add(new Token("Order.CustomerEmail", order.BillingAddress.Email)); tokens.Add(new Token("Order.BillingFirstName", order.BillingAddress.FirstName)); tokens.Add(new Token("Order.BillingLastName", order.BillingAddress.LastName)); tokens.Add(new Token("Order.BillingPhoneNumber", order.BillingAddress.PhoneNumber)); tokens.Add(new Token("Order.BillingEmail", order.BillingAddress.Email)); tokens.Add(new Token("Order.BillingFaxNumber", order.BillingAddress.FaxNumber)); tokens.Add(new Token("Order.BillingCompany", order.BillingAddress.Company)); tokens.Add(new Token("Order.BillingAddress1", order.BillingAddress.Address1)); tokens.Add(new Token("Order.BillingAddress2", order.BillingAddress.Address2)); tokens.Add(new Token("Order.BillingCity", order.BillingAddress.City)); tokens.Add(new Token("Order.BillingStateProvince", order.BillingAddress.StateProvince != null ? order.BillingAddress.StateProvince.GetLocalized(x => x.Name) : "")); tokens.Add(new Token("Order.BillingZipPostalCode", order.BillingAddress.ZipPostalCode)); tokens.Add(new Token("Order.BillingCountry", order.BillingAddress.Country != null ? order.BillingAddress.Country.GetLocalized(x => x.Name) : "")); tokens.Add(new Token("Order.ShippingMethod", order.ShippingMethod)); tokens.Add(new Token("Order.ShippingFirstName", order.ShippingAddress != null ? order.ShippingAddress.FirstName : "")); tokens.Add(new Token("Order.ShippingLastName", order.ShippingAddress != null ? order.ShippingAddress.LastName : "")); tokens.Add(new Token("Order.ShippingPhoneNumber", order.ShippingAddress != null ? order.ShippingAddress.PhoneNumber : "")); tokens.Add(new Token("Order.ShippingEmail", order.ShippingAddress != null ? order.ShippingAddress.Email : "")); tokens.Add(new Token("Order.ShippingFaxNumber", order.ShippingAddress != null ? order.ShippingAddress.FaxNumber : "")); tokens.Add(new Token("Order.ShippingCompany", order.ShippingAddress != null ? order.ShippingAddress.Company : "")); tokens.Add(new Token("Order.ShippingAddress1", order.ShippingAddress != null ? order.ShippingAddress.Address1 : "")); tokens.Add(new Token("Order.ShippingAddress2", order.ShippingAddress != null ? order.ShippingAddress.Address2 : "")); tokens.Add(new Token("Order.ShippingCity", order.ShippingAddress != null ? order.ShippingAddress.City : "")); tokens.Add(new Token("Order.ShippingStateProvince", order.ShippingAddress != null && order.ShippingAddress.StateProvince != null ? order.ShippingAddress.StateProvince.GetLocalized(x => x.Name) : "")); tokens.Add(new Token("Order.ShippingZipPostalCode", order.ShippingAddress != null ? order.ShippingAddress.ZipPostalCode : "")); tokens.Add(new Token("Order.ShippingCountry", order.ShippingAddress != null && order.ShippingAddress.Country != null ? order.ShippingAddress.Country.GetLocalized(x => x.Name) : "")); var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); var paymentMethodName = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) : order.PaymentMethodSystemName; tokens.Add(new Token("Order.PaymentMethod", paymentMethodName)); tokens.Add(new Token("Order.VatNumber", order.VatNumber)); tokens.Add(new Token("Order.Product(s)", ProductListToHtmlTable(order, languageId), true)); var language = _languageService.GetLanguageById(languageId); if (language != null && !String.IsNullOrEmpty(language.LanguageCulture)) { DateTime createdOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, TimeZoneInfo.Utc, _dateTimeHelper.GetCustomerTimeZone(order.Customer)); tokens.Add(new Token("Order.CreatedOn", createdOn.ToString("D", new CultureInfo(language.LanguageCulture)))); } else { tokens.Add(new Token("Order.CreatedOn", order.CreatedOnUtc.ToString("D"))); } //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) tokens.Add(new Token("Order.OrderURLForCustomer", string.Format("{0}orderdetails/{1}", _webHelper.GetStoreLocation(false), order.Id), true)); //event notification _eventPublisher.EntityTokensAdded(order, tokens); }
/// <summary> /// Gets a customer time zone /// </summary> /// <param name="customer">Customer</param> /// <returns>Customer time zone; if customer is null, then default store time zone</returns> public TimeZoneInfo GetCustomerTimeZone(Customer customer) { return(_dateTimeHelper.GetCustomerTimeZone(customer)); }
public void Execute() { //is plugin installed? var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("Widgets.mobSocial"); if (pluginDescriptor == null) { return; } //plugin var plugin = pluginDescriptor.Instance() as MobSocialWebApiPlugin; if (plugin == null) { return; } //the task will send reminders to customers based on the timezone they are in, we don't want to send ill-timed emails //first get all the battles int notUsedTotalPages; var allBattles = _videoBattleService.GetAll(null, null, null, null, null, null, string.Empty, null, null, out notUsedTotalPages, 1, int.MaxValue); #region to participants who have not uploaded video, that means only battles with pending status and within settings' threshold var pendingBattles = allBattles.Where(x => x.VideoBattleStatus == VideoBattleStatus.Pending && x.VotingStartDate.Subtract(DateTime.UtcNow).TotalDays <= _mobSocialSettings.VideoUploadReminderEmailThresholdDays); //TODO: Find a way to improve performance of this feature foreach (var battle in pendingBattles) { //participantVideos for this battle var participantVideos = _videoBattleVideoService.GetBattleVideos(battle.Id); //the ids of participants who have uploaded videos var participantIds = participantVideos.Select(x => x.ParticipantId); var battleParticipants = _videoBattleParticipantService.GetVideoBattleParticipants(battle.Id, VideoBattleParticipantStatus.ChallengeAccepted); //the ids of participants who need to be reminded var requireReminderParticipantIds = battleParticipants.Where(x => !participantIds.Contains(x.ParticipantId)).Select(x => x.ParticipantId).ToArray(); //send reminders to them var participantCustomers = _customerService.GetCustomersByIds(requireReminderParticipantIds); foreach (var customer in participantCustomers) { //get the current time in customer's timezone var customerDateTime = _dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, TimeZoneInfo.Utc, _dateTimeHelper.GetCustomerTimeZone(customer)); //make sure it's good time to send email, between 7:00 AM - 5:00 PM should be a good time right? if (customerDateTime.Hour >= 7 && customerDateTime.Hour <= 17) { _mobSocialMessageService.SendXDaysToBattleStartNotificationToParticipant(customer, battle, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id); } } } #endregion #region to the followers who are following the battle but haven't yet voted var openBattles = allBattles.Where(x => x.VideoBattleStatus == VideoBattleStatus.Open && x.VotingStartDate.Subtract(DateTime.UtcNow).TotalDays <= _mobSocialSettings.VideoUploadReminderEmailThresholdDays); //TODO: Find a way to improve performance of this feature foreach (var battle in openBattles) { //followers of this battle var followers = _customerFollowService.GetFollowers <VideoBattle>(battle.Id); //get the votes casted so far var votes = _videoBattleVoteService.GetVideoBattleVotes(battle.Id, null); //their customer ids var votesCustomerIds = votes.Select(x => x.ParticipantId); //and now the followers who haven't voted, need to be reminded//should not be a battle owner either var followersToRemindIds = followers.Where(x => !votesCustomerIds.Contains(x.CustomerId) && x.CustomerId != battle.ChallengerId).Select(x => x.CustomerId).ToArray(); //send reminders to them var followerCustomers = _customerService.GetCustomersByIds(followersToRemindIds); foreach (var customer in followerCustomers) { //get the current time in customer's timezone var customerDateTime = _dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, TimeZoneInfo.Utc, _dateTimeHelper.GetCustomerTimeZone(customer)); //make sure it's good time to send email, between 7:00 AM - 5:00 PM should be a good time right? if (customerDateTime.Hour >= 7 && customerDateTime.Hour <= 17) { _mobSocialMessageService.SendXDaysToBattleEndNotificationToFollower(customer, battle, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id); } } } #endregion //TODO: Send a consolidated email which contains all the battles (to participate and to vote) }