public virtual async Task <bool> IsInventorySufficientAsync(Product product, ProductSku productSku, Guid storeId, int quantity) { var inventoryData = await GetInventoryProviderOrDefault(product, productSku) .GetInventoryDataAsync(product, productSku, storeId); return(product.InventoryStrategy == InventoryStrategy.NoNeed || inventoryData.Inventory - quantity >= 0); }
public ConsumeInventoryModel(Product product, ProductSku productSku, Guid storeId, int quantity) { Product = product; ProductSku = productSku; StoreId = storeId; Quantity = quantity; }
public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, int quantity, bool increaseSold) { var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id); return(await(await _productInventoryProviderResolver.GetAsync(product)) .TryReduceInventoryAsync(model, quantity, increaseSold)); }
public virtual async Task <Product> UpdateSkuAsync(Product product, ProductSku productSku) { await CheckProductSkuNameUniqueAsync(product, productSku); await CheckProductDetailAsync(product); return(await _productRepository.UpdateAsync(product, true)); }
public virtual async Task <bool> IsInventorySufficientAsync(Product product, ProductSku productSku, int quantity) { var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id); var inventoryData = await(await _productInventoryProviderResolver.GetAsync(product)).GetInventoryDataAsync(model); return(product.InventoryStrategy == InventoryStrategy.NoNeed || inventoryData.Inventory - quantity >= 0); }
protected virtual Task CheckSkuAttributeOptionsAsync(Product product, ProductSku productSku) { if (product.ProductSkus.Where(sku => sku.Id != productSku.Id).FirstOrDefault(sku => sku.SerializedAttributeOptionIds.Equals(productSku.SerializedAttributeOptionIds)) != null) { throw new ProductSkuDuplicatedException(product.Id, productSku.SerializedAttributeOptionIds); } return(Task.CompletedTask); }
public virtual async Task <decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId) { var currentPrice = productSku.Price; foreach (var provider in ServiceProvider.GetServices <IProductDiscountProvider>()) { currentPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, currentPrice); } return(currentPrice); }
public virtual async Task <Product> CreateSkuAsync(Product product, ProductSku productSku) { // productSku.SetSerializedAttributeOptionIds(await _attributeOptionIdsSerializer.FormatAsync(productSku.SerializedAttributeOptionIds)); await CheckSkuAttributeOptionsAsync(product, productSku); await CheckProductSkuNameUniqueAsync(product, productSku); productSku.TrimCode(); product.ProductSkus.AddIfNotContains(productSku); return(await _productRepository.UpdateAsync(product, true)); }
protected virtual Task CheckProductSkuNameUniqueAsync(Product product, ProductSku productSku) { if (productSku.Name.IsNullOrEmpty()) { return(Task.CompletedTask); } if (product.ProductSkus.Where(sku => sku.Id != productSku.Id) .FirstOrDefault(sku => sku.Name == productSku.Name) != null) { throw new ProductSkuCodeDuplicatedException(product.Id, productSku.Name); } return(Task.CompletedTask); }
public async Task Should_Use_Fake_Inventory_Provider() { var product2 = new Product(ProductsTestData.Product2Id, null, ProductsTestData.Store1Id, "Default", ProductsTestData.ProductDetails2Id, "Ball", "Ball", InventoryStrategy.NoNeed, "Fake", true, false, false, null, null, 0); await ProductManager.CreateAsync(product2); var fakeSku = new ProductSku(Guid.NewGuid(), "[]", null, "USD", null, 0m, 1, 1, null, null, null); var inventoryDataModel = await ProductManager.GetInventoryDataAsync(product2, fakeSku); inventoryDataModel.ShouldNotBeNull(); inventoryDataModel.Inventory.ShouldBe(9998); }
protected virtual async Task CheckSkuAttributeOptionsAsync(Product product, ProductSku productSku) { var attributeOptionIds = (await _attributeOptionIdsSerializer.DeserializeAsync(productSku.SerializedAttributeOptionIds)) .ToList(); if (!product.ProductAttributes.TrueForAll(attribute => attribute.ProductAttributeOptions.Select(option => option.Id).Intersect(attributeOptionIds) .Count() == 1)) { throw new ProductSkuIncorrectAttributeOptionsException(product.Id, productSku.SerializedAttributeOptionIds); } if (product.ProductSkus.Where(sku => sku.Id != productSku.Id).FirstOrDefault(sku => sku.SerializedAttributeOptionIds.Equals(productSku.SerializedAttributeOptionIds)) != null) { throw new ProductSkuDuplicatedException(product.Id, productSku.SerializedAttributeOptionIds); } }
public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku) { return(await _productInventoryProvider.GetInventoryDataAsync(product, productSku)); }
public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool increaseSold) { var productInventory = await _productInventoryRepository.GetAsync(x => x.ProductSkuId == productSku.Id); return(await TryReduceInventoryAsync(productInventory, quantity, increaseSold)); }
public virtual Task <decimal> GetPriceAsync(Product product, ProductSku productSku) { return(Task.FromResult(productSku.Price)); }
protected virtual IProductInventoryProvider GetInventoryProviderOrDefault(Product product, ProductSku productSku) { var providerName = !productSku.SpecifiedInventoryProviderName.IsNullOrWhiteSpace() ? productSku.SpecifiedInventoryProviderName : !product.SpecifiedInventoryProviderName.IsNullOrWhiteSpace() ? product.SpecifiedInventoryProviderName : "Default"; InventoryProviders ??= ServiceProvider.GetServices <IProductInventoryProvider>() .ToDictionary(p => p.ProviderName, p => p); return(InventoryProviders.GetOrDefault(providerName) ?? InventoryProviders["Default"]); }
public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool increaseSold) { return(await GetInventoryProviderOrDefault(product, productSku) .TryReduceInventoryAsync(product, productSku, storeId, quantity, increaseSold)); }
public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId) { return(await GetInventoryProviderOrDefault(product, productSku) .GetInventoryDataAsync(product, productSku, storeId)); }
public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity) { return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, storeId, quantity)); }
public virtual async Task <Product> DeleteSkuAsync(Product product, ProductSku productSku) { product.ProductSkus.Remove(productSku); return(await _productRepository.UpdateAsync(product, true)); }
public virtual async Task <bool> TryIncreaseInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool reduceSold) { return(await _productInventoryProvider.TryIncreaseInventoryAsync(product, productSku, storeId, quantity, reduceSold)); }
public virtual async Task <PriceDataModel> GetRealPriceAsync(Product product, ProductSku productSku) { var price = await _productPriceProvider.GetPriceAsync(product, productSku); var discountedPrice = price; // Todo: provider execution ordering. foreach (var provider in LazyServiceProvider.LazyGetService <IEnumerable <IProductDiscountProvider> >()) { discountedPrice = await provider.GetDiscountedPriceAsync(product, productSku, discountedPrice); } return(new PriceDataModel { Price = price, DiscountedPrice = discountedPrice }); }
public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId) { return(await _productInventoryRepository.GetInventoryDataAsync(productSku.Id)); }
public virtual async Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId) { return(await _productInventoryProvider.GetInventoryAsync(product, productSku, storeId)); }
public virtual Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId) { return(Task.FromResult(productSku.Inventory)); }
public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, int quantity, bool increaseSold) { return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, quantity, increaseSold)); }
public virtual async Task <PriceDataModel> GetProductPriceAsync(Product product, ProductSku productSku, Guid storeId) { var price = await _productPriceProvider.GetPriceAsync(product, productSku, storeId); var discountedPrice = price; foreach (var provider in ServiceProvider.GetServices <IProductDiscountProvider>()) { discountedPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, discountedPrice); } return(new PriceDataModel { Price = price, DiscountedPrice = discountedPrice }); }
public virtual Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity) { return(Task.FromResult(productSku.TryReduceInventory(quantity))); }
public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku) { var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id); return(await(await _productInventoryProviderResolver.GetAsync(product)).GetInventoryDataAsync(model)); }