/// <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 = GetLocalizedActiveMessageTemplate("Customer.BackInStock", languageId, store.Id); if (messageTemplate == null) return 0; //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store); _messageTokenProvider.AddCustomerTokens(tokens, subscription.Customer); _messageTokenProvider.AddBackInStockTokens(tokens, subscription); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); 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 virtual void AddBackInStockTokens(IList<Token> tokens, BackInStockSubscription subscription) { tokens.Add(new Token("BackInStockSubscription.ProductName", subscription.Product.Name)); //event notification _eventPublisher.EntityTokensAdded(subscription, tokens); }
public ActionResult BackInStockSubscribePopupPOST(int id /* productId */) { var product = _productService.GetProductById(id); if (product == null || product.Deleted) throw new ArgumentException("No product found with the specified id"); if (!_services.WorkContext.CurrentCustomer.IsRegistered()) return Content(T("BackInStockSubscriptions.OnlyRegistered")); if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.StockQuantity <= 0) { //out of stock var subscription = _backInStockSubscriptionService .FindSubscription(_services.WorkContext.CurrentCustomer.Id, product.Id, _services.StoreContext.CurrentStore.Id); if (subscription != null) { //unsubscribe _backInStockSubscriptionService.DeleteSubscription(subscription); return Content("Unsubscribed"); } else { if (_backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(_services.WorkContext.CurrentCustomer.Id, _services.StoreContext.CurrentStore.Id, 0, 1) .TotalCount >= _catalogSettings.MaximumBackInStockSubscriptions) return Content(string.Format(T("BackInStockSubscriptions.MaxSubscriptions"), _catalogSettings.MaximumBackInStockSubscriptions)); //subscribe subscription = new BackInStockSubscription() { Customer = _services.WorkContext.CurrentCustomer, Product = product, StoreId = _services.StoreContext.CurrentStore.Id, CreatedOnUtc = DateTime.UtcNow }; _backInStockSubscriptionService.InsertSubscription(subscription); return Content("Subscribed"); } } else { return Content(T("BackInStockSubscriptions.NotAllowed")); } }
public virtual void AddBackInStockTokens(IList<Token> tokens, BackInStockSubscription subscription) { var customerLangId = subscription.Customer.GetAttribute<int>( SystemCustomerAttributeNames.LanguageId, _attrService, _storeContext.CurrentStore.Id); var store = _storeService.GetStoreById(subscription.StoreId); var productLink = "{0}{1}".FormatWith(store.Url, subscription.Product.GetSeName(customerLangId, _urlRecordService, _languageService)); tokens.Add(new Token("BackInStockSubscription.ProductName", "<a href='{0}'>{1}</a>".FormatWith(productLink, subscription.Product.Name), true)); //event notification _eventPublisher.EntityTokensAdded(subscription, tokens); }