// 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(int productId) { var product = await _productService.GetProductByIdAsync(productId); if (product == null || product.Deleted) { throw new ArgumentException("No product found with the specified id"); } var model = new BackInStockSubscribeModel { ProductId = product.Id, ProductName = await _localizationService.GetLocalizedAsync(product, x => x.Name), ProductSeName = await _urlRecordService.GetSeNameAsync(product), IsCurrentCustomerRegistered = await _customerService.IsRegisteredAsync(await _workContext.GetCurrentCustomerAsync()), MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions, CurrentNumberOfBackInStockSubscriptions = (await _backInStockSubscriptionService .GetAllSubscriptionsByCustomerIdAsync((await _workContext.GetCurrentCustomerAsync()).Id, (await _storeContext.GetCurrentStoreAsync()).Id, 0, 1)) .TotalCount }; if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && await _productService.GetTotalStockQuantityAsync(product) <= 0) { //out of stock model.SubscriptionAllowed = true; model.AlreadySubscribed = await _backInStockSubscriptionService .FindSubscriptionAsync((await _workContext.GetCurrentCustomerAsync()).Id, product.Id, (await _storeContext.GetCurrentStoreAsync()).Id) != null; } return(PartialView(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> /// Returns content view for stock subscribe popup. /// </summary> /// <param name="id">Represents the <see cref="Product.Id"/> of the corresponding subscription.</param> public async Task <IActionResult> BackInStockSubscribe(int id) { var product = await _db.Products.FindByIdAsync(id, false); if (product == null || product.IsSystemProduct || !product.Published) { return(NotFound()); } var customer = Services.WorkContext.CurrentCustomer; var store = Services.StoreContext.CurrentStore; var model = new BackInStockSubscribeModel { ProductId = product.Id, ProductName = product.GetLocalized(x => x.Name), ProductSeName = await product.GetActiveSlugAsync(), IsCurrentCustomerRegistered = customer.IsRegistered(), MaximumBackInStockSubscriptions = _catalogSettings.MaximumBackInStockSubscriptions, CurrentNumberOfBackInStockSubscriptions = await _db.BackInStockSubscriptions .ApplyStandardFilter(customerId : customer.Id, storeId : store.Id) .CountAsync() }; if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.BackorderMode == BackorderMode.NoBackorders && product.AllowBackInStockSubscriptions && product.StockQuantity <= 0) { // Out of stock. model.SubscriptionAllowed = true; model.AlreadySubscribed = await _stockSubscriptionService.Value.IsSubscribedAsync(product, customer, store.Id); } return(View("BackInStockSubscribePopup", model)); }