// Product details page > back in stock subscribe public ActionResult SubscribePopup(int productId) { var product = _productService.GetProductById(productId); if (product == null || product.Deleted) { throw new ArgumentException("No product found with the specified id"); } var model = new BackInStockSubscribeModel(); model.ProductId = product.Id; model.ProductName = product.GetLocalized(x => x.Name); model.ProductSeName = product.GetSeName(); model.IsCurrentCustomerRegistered = _workContext.CurrentCustomer.IsRegistered(); model.MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions; model.CurrentNumberOfBackInStockSubscriptions = _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id, 0, 1) .TotalCount; if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.GetTotalStockQuantity() <= 0) { //out of stock model.SubscriptionAllowed = true; model.AlreadySubscribed = _backInStockSubscriptionService .FindSubscription(_workContext.CurrentCustomer.Id, product.Id, _storeContext.CurrentStore.Id) != null; } return(View(model)); }
public ActionResult BackInStockSubscribePopup(int id /* productId */) { var product = _productService.GetProductById(id); if (product == null || product.Deleted || product.IsSystemProduct) { throw new ArgumentException(T("Products.NotFound", id)); } var customer = _services.WorkContext.CurrentCustomer; var store = _services.StoreContext.CurrentStore; var model = new BackInStockSubscribeModel(); model.ProductId = product.Id; model.ProductName = product.GetLocalized(x => x.Name); model.ProductSeName = product.GetSeName(); model.IsCurrentCustomerRegistered = customer.IsRegistered(); model.MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions; model.CurrentNumberOfBackInStockSubscriptions = _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(customer.Id, store.Id, 0, 1) .TotalCount; if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.StockQuantity <= 0) { // Out of stock. model.SubscriptionAllowed = true; model.AlreadySubscribed = _backInStockSubscriptionService.FindSubscription(customer.Id, product.Id, store.Id) != null; } return(View("BackInStockSubscribePopup", model)); }
// Product details page > back in stock subscribe public virtual async Task <IActionResult> SubscribePopup(string productId) { var product = await _productService.GetProductById(productId); if (product == null) { throw new ArgumentException("No product found with the specified id"); } var customer = _workContext.CurrentCustomer; var store = _storeContext.CurrentStore; var model = new BackInStockSubscribeModel(); model.ProductId = product.Id; model.ProductName = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id); model.ProductSeName = product.GetSeName(_workContext.WorkingLanguage.Id); model.IsCurrentCustomerRegistered = customer.IsRegistered(); model.MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions; model.CurrentNumberOfBackInStockSubscriptions = (await _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(customer.Id, store.Id, 0, 1)) .TotalCount; if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.GetTotalStockQuantity(warehouseId: store.DefaultWarehouseId) <= 0) { //out of stock model.SubscriptionAllowed = true; model.AlreadySubscribed = (await _backInStockSubscriptionService .FindSubscription(customer.Id, product.Id, store.Id, product.UseMultipleWarehouses ? store.DefaultWarehouseId : "")) != null; } return(View(model)); }
// Product details page > back in stock subscribe public virtual IActionResult SubscribePopup(int productId) { var product = _productService.GetProductById(productId); if (product == null || product.Deleted) { throw new ArgumentException("No product found with the specified id"); } BackInStockSubscribeModel model = new BackInStockSubscribeModel(); model = new BackInStockSubscribeModel { ProductId = product.Id, ImageUrl = _pictureService.GetPictureUrl(product.ProductPictures.FirstOrDefault()?.Picture), //ProductCategoryName = product.ProductCategories.FirstOrDefault()?.Category.ParentCategoryId == null ? product.ProductCategories.FirstOrDefault()?.Category.Name : _categoryService.GetCategoryById(product.ProductCategories.FirstOrDefault()?.Category.ParentCategoryId ?? 0).Name, ProductPrice = _priceFormatter.FormatPrice(product.Price), ProductName = _localizationService.GetLocalized(product, x => x.Name), ProductSeName = _urlRecordService.GetSeName(product), IsCurrentCustomerRegistered = _workContext.CurrentCustomer.IsRegistered(), MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions, CurrentNumberOfBackInStockSubscriptions = _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id, 0, 1) .TotalCount }; if (product.BackorderMode == BackorderMode.NoBackorders && _productService.GetTotalStockQuantity(product) <= 0) { //out of stock model.SubscriptionAllowed = true; model.AlreadySubscribed = _backInStockSubscriptionService .FindSubscription(_workContext.CurrentCustomer.Id, product.Id, _storeContext.CurrentStore.Id) != null; } return(PartialView(model)); }
/// <summary> /// Permanent delete of customer /// </summary> /// <param name="customer">Customer</param> public virtual void PermanentDeleteCustomer(Customer customer) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } //blog comments var blogComments = _blogService.GetAllComments(customerId: customer.Id); _blogService.DeleteBlogComments(blogComments); //news comments var newsComments = _newsService.GetAllComments(customerId: customer.Id); _newsService.DeleteNewsComments(newsComments); //back in stock subscriptions var backInStockSubscriptions = _backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id); foreach (var backInStockSubscription in backInStockSubscriptions) { _backInStockSubscriptionService.DeleteSubscription(backInStockSubscription); } //product review var productReviews = _productService.GetAllProductReviews(customerId: customer.Id, approved: null); var reviewedProducts = _productService.GetProductsByIds(productReviews.Select(p => p.ProductId).Distinct().ToArray()); _productService.DeleteProductReviews(productReviews); //update product totals foreach (var product in reviewedProducts) { _productService.UpdateProductReviewTotals(product); } //external authentication record foreach (var ear in customer.ExternalAuthenticationRecords) { _externalAuthenticationService.DeleteExternalAuthenticationRecord(ear); } //forum subscriptions var forumSubscriptions = _forumService.GetAllSubscriptions(customer.Id); foreach (var forumSubscription in forumSubscriptions) { _forumService.DeleteSubscription(forumSubscription); } //shopping cart items foreach (var sci in customer.ShoppingCartItems) { _shoppingCartService.DeleteShoppingCartItem(sci); } //private messages (sent) foreach (var pm in _forumService.GetAllPrivateMessages(0, customer.Id, 0, null, null, null, null)) { _forumService.DeletePrivateMessage(pm); } //private messages (received) foreach (var pm in _forumService.GetAllPrivateMessages(0, 0, customer.Id, null, null, null, null)) { _forumService.DeletePrivateMessage(pm); } //newsletter var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, store.Id); if (newsletter != null) { _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter); } } //addresses foreach (var address in customer.Addresses) { _customerService.RemoveCustomerAddress(customer, address); _customerService.UpdateCustomer(customer); //now delete the address record _addressService.DeleteAddress(address); } //generic attributes var keyGroup = customer.GetUnproxiedEntityType().Name; var genericAttributes = _genericAttributeService.GetAttributesForEntity(customer.Id, keyGroup); _genericAttributeService.DeleteAttributes(genericAttributes); //ignore ActivityLog //ignore ForumPost, ForumTopic, ignore ForumPostVote //ignore Log //ignore PollVotingRecord //ignore ProductReviewHelpfulness //ignore RecurringPayment //ignore ReturnRequest //ignore RewardPointsHistory //and we do not delete orders //remove from Registered role, add to Guest one if (customer.IsRegistered()) { var registeredRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.RegisteredRoleName); customer.RemoveCustomerRoleMapping( customer.CustomerCustomerRoleMappings.FirstOrDefault(mapping => mapping.CustomerRoleId == registeredRole.Id)); } if (!customer.IsGuest()) { var guestRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.GuestsRoleName); customer.AddCustomerRoleMapping(new CustomerCustomerRoleMapping { CustomerRole = guestRole }); } var email = customer.Email; //clear other information customer.Email = string.Empty; customer.EmailToRevalidate = string.Empty; customer.Username = string.Empty; customer.Active = false; customer.Deleted = true; _customerService.UpdateCustomer(customer); //raise event _eventPublisher.Publish(new CustomerPermanentlyDeleted(customer.Id, email)); }
public virtual IDictionary <string, object> ExportCustomer(Customer customer) { Guard.NotNull(customer, nameof(customer)); var ignoreMemberNames = new string[] { "WishlistUrl", "EditUrl", "PasswordRecoveryURL", "BillingAddress.NameLine", "BillingAddress.StreetLine", "BillingAddress.CityLine", "BillingAddress.CountryLine", "ShippingAddress.NameLine", "ShippingAddress.StreetLine", "ShippingAddress.CityLine", "ShippingAddress.CountryLine" }; var model = _messageModelProvider.CreateModelPart(customer, true, ignoreMemberNames) as IDictionary <string, object>; if (model != null) { // Roles model["CustomerRoles"] = customer.CustomerRoles.Select(x => x.Name).ToArray(); // Generic attributes var attributes = _genericAttributeService.GetAttributesForEntity(customer.Id, "Customer"); if (attributes.Any()) { model["Attributes"] = _messageModelProvider.CreateModelPart(attributes, true); } // Order history var orders = customer.Orders.Where(x => !x.Deleted); if (orders.Any()) { ignoreMemberNames = new string[] { "Disclaimer", "ConditionsOfUse", "Url", "CheckoutAttributes", "Items.DownloadUrl", "Items.Product.Description", "Items.Product.Url", "Items.Product.Thumbnail", "Items.Product.ThumbnailLg", "Items.BundleItems.Product.Description", "Items.BundleItems.Product.Url", "Items.BundleItems.Product.Thumbnail", "Items.BundleItems.Product.ThumbnailLg", "Billing.NameLine", "Billing.StreetLine", "Billing.CityLine", "Billing.CountryLine", "Shipping.NameLine", "Shipping.StreetLine", "Shipping.CityLine", "Shipping.CountryLine" }; model["Orders"] = orders.Select(x => _messageModelProvider.CreateModelPart(x, true, ignoreMemberNames)).ToList(); } // Return Request var returnRequests = customer.ReturnRequests; if (returnRequests.Any()) { model["ReturnRequests"] = returnRequests.Select(x => _messageModelProvider.CreateModelPart(x, true, "Url")).ToList(); } // Wallet var walletHistory = customer.WalletHistory; if (walletHistory.Any()) { model["WalletHistory"] = walletHistory.Select(x => _messageModelProvider.CreateModelPart(x, true, "WalletUrl")).ToList(); } // Forum topics var forumTopics = customer.ForumTopics; if (forumTopics.Any()) { model["ForumTopics"] = forumTopics.Select(x => _messageModelProvider.CreateModelPart(x, true, "Url")).ToList(); } // Forum posts var forumPosts = customer.ForumPosts; if (forumPosts.Any()) { model["ForumPosts"] = forumPosts.Select(x => _messageModelProvider.CreateModelPart(x, true)).ToList(); } // Product reviews var productReviews = customer.CustomerContent.OfType <ProductReview>(); if (productReviews.Any()) { model["ProductReviews"] = productReviews.Select(x => _messageModelProvider.CreateModelPart(x, true)).ToList(); } // News comments var newsComments = customer.CustomerContent.OfType <NewsComment>(); if (newsComments.Any()) { model["NewsComments"] = newsComments.Select(x => _messageModelProvider.CreateModelPart(x, true)).ToList(); } // Blog comments var blogComments = customer.CustomerContent.OfType <BlogComment>(); if (blogComments.Any()) { model["BlogComments"] = blogComments.Select(x => _messageModelProvider.CreateModelPart(x, true)).ToList(); } // Product review helpfulness var helpfulness = customer.CustomerContent.OfType <ProductReviewHelpfulness>(); if (helpfulness.Any()) { ignoreMemberNames = new string[] { "CustomerId", "UpdatedOn" }; model["ProductReviewHelpfulness"] = helpfulness.Select(x => _messageModelProvider.CreateModelPart(x, true, ignoreMemberNames)).ToList(); } // Poll voting var pollVotings = customer.CustomerContent.OfType <PollVotingRecord>(); if (pollVotings.Any()) { ignoreMemberNames = new string[] { "CustomerId", "UpdatedOn" }; model["PollVotings"] = pollVotings.Select(x => _messageModelProvider.CreateModelPart(x, true, ignoreMemberNames)).ToList(); } // Forum subscriptions var forumSubscriptions = _forumService.GetAllSubscriptions(customer.Id, 0, 0, 0, int.MaxValue); if (forumSubscriptions.Any()) { model["ForumSubscriptions"] = forumSubscriptions.Select(x => _messageModelProvider.CreateModelPart(x, true, "CustomerId")).ToList(); } // BackInStock subscriptions var backInStockSubscriptions = _backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id, 0, 0, int.MaxValue); if (backInStockSubscriptions.Any()) { model["BackInStockSubscriptions"] = backInStockSubscriptions.Select(x => _messageModelProvider.CreateModelPart(x, true, "CustomerId")).ToList(); } // INFO: we're not going to export: // - Private messages // - Activity log // It doesn't feel right and GDPR rules are not very clear about this. Let's wait and see :-) // Publish event to give plugin devs a chance to attach external data. _services.EventPublisher.Publish(new CustomerExportedEvent(customer, model)); } return(model); }
public virtual async Task <IActionResult> SubscribePopup(string productId, IFormCollection form) { var product = await _productService.GetProductById(productId); if (product == null) { throw new ArgumentException("No product found with the specified id"); } var customer = _workContext.CurrentCustomer; string warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? form["WarehouseId"].ToString() : product.UseMultipleWarehouses ? _storeContext.CurrentStore.DefaultWarehouseId : (string.IsNullOrEmpty(_storeContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId : _storeContext.CurrentStore.DefaultWarehouseId); if (!customer.IsRegistered()) { return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.OnlyRegistered") })); } if ((product.ManageInventoryMethod == ManageInventoryMethod.ManageStock) && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.GetTotalStockQuantity(warehouseId: warehouseId) <= 0) { var subscription = await _backInStockSubscriptionService .FindSubscription(customer.Id, product.Id, null, _storeContext.CurrentStore.Id, warehouseId); if (subscription != null) { //subscription already exists //unsubscribe await _backInStockSubscriptionService.DeleteSubscription(subscription); return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.Unsubscribed") })); } //subscription does not exist //subscribe if ((await _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(customer.Id, _storeContext.CurrentStore.Id, 0, 1)) .TotalCount >= _catalogSettings.MaximumBackInStockSubscriptions) { return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = string.Format(_localizationService.GetResource("BackInStockSubscriptions.MaxSubscriptions"), _catalogSettings.MaximumBackInStockSubscriptions) })); } subscription = new BackInStockSubscription { CustomerId = customer.Id, ProductId = product.Id, StoreId = _storeContext.CurrentStore.Id, WarehouseId = warehouseId, CreatedOnUtc = DateTime.UtcNow }; await _backInStockSubscriptionService.InsertSubscription(subscription); return(Json(new { subscribe = true, buttontext = _localizationService.GetResource("BackInStockSubscriptions.DeleteNotifyWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.Subscribed") })); } if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions) { var attributes = await _mediator.Send(new GetParseProductAttributes() { Product = product, Form = form }); var subscription = await _backInStockSubscriptionService .FindSubscription(customer.Id, product.Id, attributes, _storeContext.CurrentStore.Id, warehouseId); if (subscription != null) { //subscription already exists //unsubscribe await _backInStockSubscriptionService.DeleteSubscription(subscription); return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.Unsubscribed") })); } //subscription does not exist //subscribe if ((await _backInStockSubscriptionService .GetAllSubscriptionsByCustomerId(customer.Id, _storeContext.CurrentStore.Id, 0, 1)) .TotalCount >= _catalogSettings.MaximumBackInStockSubscriptions) { return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = string.Format(_localizationService.GetResource("BackInStockSubscriptions.MaxSubscriptions"), _catalogSettings.MaximumBackInStockSubscriptions) })); } subscription = new BackInStockSubscription { CustomerId = customer.Id, ProductId = product.Id, Attributes = attributes, StoreId = _storeContext.CurrentStore.Id, WarehouseId = warehouseId, CreatedOnUtc = DateTime.UtcNow }; await _backInStockSubscriptionService.InsertSubscription(subscription); return(Json(new { subscribe = true, buttontext = _localizationService.GetResource("BackInStockSubscriptions.DeleteNotifyWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.Subscribed") })); } return(Json(new { subscribe = false, buttontext = _localizationService.GetResource("BackInStockSubscriptions.NotifyMeWhenAvailable"), resource = _localizationService.GetResource("BackInStockSubscriptions.NotAllowed") })); }