/// <summary> /// Sends a 'Back in stock' notification message to a customer /// </summary> /// <param name="subscription">Subscription</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public virtual int SendBackInStockNotification(BackInStockSubscription subscription, int languageId) { if (subscription == null) throw new ArgumentNullException("subscription"); var store = _storeService.GetStoreById(subscription.StoreId) ?? _storeContext.CurrentStore; languageId = EnsureLanguageIsActive(languageId, store.Id); var messageTemplate = GetActiveMessageTemplate("Customer.BackInStock", store.Id); if (messageTemplate == null) return 0; //email account var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount); _messageTokenProvider.AddCustomerTokens(tokens, subscription.Customer); _messageTokenProvider.AddBackInStockTokens(tokens, subscription); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var customer = subscription.Customer; var toEmail = customer.Email; var toName = customer.GetFullName(); return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName); }
public void Can_save_and_load_backInStockSubscription() { var backInStockSubscription = new BackInStockSubscription { Product = GetTestProduct(), Customer = new Customer { CustomerGuid = Guid.NewGuid(), AdminComment = "some comment here", Active = true, Deleted = false, CreatedOnUtc = new DateTime(2010, 01, 01), LastActivityDateUtc = new DateTime(2010, 01, 02) }, CreatedOnUtc = new DateTime(2010, 01, 02) }; var fromDb = SaveAndLoadEntity(backInStockSubscription); fromDb.ShouldNotBeNull(); fromDb.Product.ShouldNotBeNull(); fromDb.Customer.ShouldNotBeNull(); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 02)); }
/// <summary> /// Delete a back in stock subscription /// </summary> /// <param name="subscription">Subscription</param> public virtual void DeleteSubscription(BackInStockSubscription subscription) { if (subscription == null) throw new ArgumentNullException("subscription"); _backInStockSubscriptionRepository.Delete(subscription); //event notification _eventPublisher.EntityDeleted(subscription); }
public void Can_save_and_load_backInStockSubscription() { var backInStockSubscription = new BackInStockSubscription() { Store = new Store { Name = "Store 1", Url = "http://www.yourstore.com", }, ProductVariant = new ProductVariant { Name = "Product variant name 1", CreatedOnUtc = new DateTime(2010, 01, 03), UpdatedOnUtc = new DateTime(2010, 01, 04), Product = new Product() { Name = "Name 1", Published = true, Deleted = false, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02) } }, Customer = new Customer { CustomerGuid = Guid.NewGuid(), AdminComment = "some comment here", Active = true, Deleted = false, CreatedOnUtc = new DateTime(2010, 01, 01), LastActivityDateUtc = new DateTime(2010, 01, 02) }, CreatedOnUtc = new DateTime(2010, 01, 02) }; var fromDb = SaveAndLoadEntity(backInStockSubscription); fromDb.ShouldNotBeNull(); fromDb.Store.ShouldNotBeNull(); fromDb.ProductVariant.ShouldNotBeNull(); fromDb.ProductVariant.Name.ShouldEqual("Product variant name 1"); fromDb.Customer.ShouldNotBeNull(); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 02)); }
/// <summary> /// Sends a 'Back in stock' notification message to a customer /// </summary> /// <param name="subscription">Subscription</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public virtual int SendBackInStockNotification(BackInStockSubscription subscription, int languageId) { if (subscription == null) throw new ArgumentNullException("subscription"); languageId = EnsureLanguageIsActive(languageId); var messageTemplate = GetLocalizedActiveMessageTemplate("Customer.BackInStock", languageId); if (messageTemplate == null) return 0; var subscriptionTokens = GenerateTokens(subscription); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); var customer = subscription.Customer; var toEmail = customer.Email; var toName = customer.GetFullName(); return SendNotification(messageTemplate, emailAccount, languageId, subscriptionTokens, toEmail, toName); }
private IList<Token> GenerateTokens(BackInStockSubscription stockSubscription) { var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens); _messageTokenProvider.AddCustomerTokens(tokens, stockSubscription.Customer); _messageTokenProvider.AddBackInStockTokens(tokens, stockSubscription); return tokens; }
public ActionResult SubscribePopupPOST(int productId) { var product = _productService.GetProductById(productId); if (product == null || product.Deleted) throw new ArgumentException("No product found with the specified id"); if (!_workContext.CurrentCustomer.IsRegistered()) return Content(_localizationService.GetResource("BackInStockSubscriptions.OnlyRegistered")); if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.GetTotalStockQuantity() <= 0) { //out of stock var subscription = _backInStockSubscriptionService .FindSubscription(_workContext.CurrentCustomer.Id, product.Id, _storeContext.CurrentStore.Id); if (subscription != null) { //subscription already exists //unsubscribe _backInStockSubscriptionService.DeleteSubscription(subscription); return Content("Unsubscribed"); } //subscription does not exist //subscribe if (_backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id, 0, 1) .TotalCount >= _catalogSettings.MaximumBackInStockSubscriptions) { return Content(string.Format(_localizationService.GetResource("BackInStockSubscriptions.MaxSubscriptions"), _catalogSettings.MaximumBackInStockSubscriptions)); } subscription = new BackInStockSubscription { Customer = _workContext.CurrentCustomer, Product = product, StoreId = _storeContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }; _backInStockSubscriptionService.InsertSubscription(subscription); return Content("Subscribed"); } //subscription not possible return Content(_localizationService.GetResource("BackInStockSubscriptions.NotAllowed")); }
public virtual void AddBackInStockTokens(IList<Token> tokens, BackInStockSubscription subscription) { tokens.Add(new Token("BackInStockSubscription.ProductName", subscription.Product.Name)); //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) var productUrl = string.Format("{0}{1}", GetStoreUrl(subscription.StoreId), subscription.Product.GetSeName()); tokens.Add(new Token("BackInStockSubscription.ProductUrl", productUrl, true)); //event notification _eventPublisher.EntityTokensAdded(subscription, tokens); }
public ActionResult BackInStockSubscribePopupPOST(int productVariantId) { var variant = _productService.GetProductVariantById(productVariantId); if (variant == null || variant.Deleted) throw new ArgumentException("No product variant found with the specified id"); if (!_workContext.CurrentCustomer.IsRegistered()) return Content(_localizationService.GetResource("BackInStockSubscriptions.OnlyRegistered")); if (variant.ManageInventoryMethod == ManageInventoryMethod.ManageStock && variant.BackorderMode == BackorderMode.NoBackorders && variant.AllowBackInStockSubscriptions && variant.StockQuantity <= 0) { //out of stock var subscription = _backInStockSubscriptionService.FindSubscription(_workContext.CurrentCustomer.Id, variant.Id); if (subscription != null) { //unsubscribe _backInStockSubscriptionService.DeleteSubscription(subscription); return Content("Unsubscribed"); } else { if (_backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(_workContext.CurrentCustomer.Id, 0, 1).TotalCount >= _catalogSettings.MaximumBackInStockSubscriptions) return Content(string.Format(_localizationService.GetResource("BackInStockSubscriptions.MaxSubscriptions"), _catalogSettings.MaximumBackInStockSubscriptions)); //subscribe subscription = new BackInStockSubscription() { Customer = _workContext.CurrentCustomer, ProductVariant = variant, CreatedOnUtc = DateTime.UtcNow }; _backInStockSubscriptionService.InsertSubscription(subscription); return Content("Subscribed"); } } else { return Content(_localizationService.GetResource("BackInStockSubscriptions.NotAllowed")); } }
public virtual void AddBackInStockTokens(IList<Token> tokens, BackInStockSubscription subscription) { tokens.Add(new Token("BackInStockSubscription.ProductName", subscription.ProductVariant.FullProductName)); }
public virtual void AddBackInStockTokens(IList<Token> tokens, BackInStockSubscription subscription) { tokens.Add(new Token("BackInStockSubscription.ProductName", subscription.ProductVariant.FullProductName)); //event notification _eventPublisher.EntityTokensAdded(subscription, tokens); }