public LiquidOutOfStockSubscription(Product product, OutOfStockSubscription outOfStockSubscription, Store store, Language language) { _outOfStockSubscription = outOfStockSubscription; _product = product; _store = store; _language = language; AdditionalTokens = new Dictionary <string, string>(); }
public LiquidObjectBuilder AddOutOfStockTokens(Product product, OutOfStockSubscription subscription, Store store, Language language) { _chain.Add(async liquidObject => { var liquidOutOfStockSubscription = new LiquidOutOfStockSubscription(product, subscription, store, language); liquidObject.OutOfStockSubscription = liquidOutOfStockSubscription; await _mediator.EntityTokensAdded(subscription, liquidOutOfStockSubscription, liquidObject); }); return(this); }
/// <summary> /// Delete a out of stock subscription /// </summary> /// <param name="subscription">Subscription</param> public virtual async Task DeleteSubscription(OutOfStockSubscription subscription) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } await _outOfStockSubscriptionRepository.DeleteAsync(subscription); //event notification await _mediator.EntityDeleted(subscription); }
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 ? _workContext.CurrentStore.DefaultWarehouseId : (string.IsNullOrEmpty(_workContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId : _workContext.CurrentStore.DefaultWarehouseId); if (!await _groupService.IsRegistered(customer)) { return(Json(new { subscribe = false, buttontext = _translationService.GetResource("OutOfStockSubscriptions.NotifyMeWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.OnlyRegistered") })); } if ((product.ManageInventoryMethodId == ManageInventoryMethod.ManageStock) && product.BackorderModeId == BackorderMode.NoBackorders && product.AllowOutOfStockSubscriptions && _stockQuantityService.GetTotalStockQuantity(product, warehouseId: warehouseId) <= 0) { var subscription = await _outOfStockSubscriptionService .FindSubscription(customer.Id, product.Id, null, _workContext.CurrentStore.Id, warehouseId); if (subscription != null) { //subscription already exists //unsubscribe await _outOfStockSubscriptionService.DeleteSubscription(subscription); return(Json(new { subscribe = false, buttontext = _translationService.GetResource("OutOfStockSubscriptions.NotifyMeWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.Unsubscribed") })); } //subscription does not exist //subscribe subscription = new OutOfStockSubscription { CustomerId = customer.Id, ProductId = product.Id, StoreId = _workContext.CurrentStore.Id, WarehouseId = warehouseId, CreatedOnUtc = DateTime.UtcNow }; await _outOfStockSubscriptionService.InsertSubscription(subscription); return(Json(new { subscribe = true, buttontext = _translationService.GetResource("OutOfStockSubscriptions.DeleteNotifyWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.Subscribed") })); } if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes && product.BackorderModeId == BackorderMode.NoBackorders && product.AllowOutOfStockSubscriptions) { var attributes = await _mediator.Send(new GetParseProductAttributes() { Product = product, Form = form }); var subscription = await _outOfStockSubscriptionService .FindSubscription(customer.Id, product.Id, attributes, _workContext.CurrentStore.Id, warehouseId); if (subscription != null) { //subscription already exists //unsubscribe await _outOfStockSubscriptionService.DeleteSubscription(subscription); return(Json(new { subscribe = false, buttontext = _translationService.GetResource("OutOfStockSubscriptions.NotifyMeWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.Unsubscribed") })); } //subscription does not exist //subscribe subscription = new OutOfStockSubscription { CustomerId = customer.Id, ProductId = product.Id, Attributes = attributes, AttributeInfo = !attributes.Any() ? "" : await _productAttributeFormatter.FormatAttributes(product, attributes), StoreId = _workContext.CurrentStore.Id, WarehouseId = warehouseId, CreatedOnUtc = DateTime.UtcNow }; await _outOfStockSubscriptionService.InsertSubscription(subscription); return(Json(new { subscribe = true, buttontext = _translationService.GetResource("OutOfStockSubscriptions.DeleteNotifyWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.Subscribed") })); } return(Json(new { subscribe = false, buttontext = _translationService.GetResource("OutOfStockSubscriptions.NotifyMeWhenAvailable"), resource = _translationService.GetResource("OutOfStockSubscriptions.NotAllowed") })); }