Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public ConsumeInventoryModel(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     Product    = product;
     ProductSku = productSku;
     StoreId    = storeId;
     Quantity   = quantity;
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        public virtual async Task <Product> UpdateSkuAsync(Product product, ProductSku productSku)
        {
            await CheckProductSkuNameUniqueAsync(product, productSku);

            await CheckProductDetailAsync(product);

            return(await _productRepository.UpdateAsync(product, true));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku)
 {
     return(await _productInventoryProvider.GetInventoryDataAsync(product, productSku));
 }
Esempio n. 13
0
        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));
 }
Esempio n. 15
0
        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"]);
        }
Esempio n. 16
0
 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));
 }
Esempio n. 17
0
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await GetInventoryProviderOrDefault(product, productSku)
            .GetInventoryDataAsync(product, productSku, storeId));
 }
Esempio n. 18
0
 public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, storeId, quantity));
 }
Esempio n. 19
0
        public virtual async Task <Product> DeleteSkuAsync(Product product, ProductSku productSku)
        {
            product.ProductSkus.Remove(productSku);

            return(await _productRepository.UpdateAsync(product, true));
        }
Esempio n. 20
0
 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));
 }
Esempio n. 21
0
        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
            });
        }
Esempio n. 22
0
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await _productInventoryRepository.GetInventoryDataAsync(productSku.Id));
 }
Esempio n. 23
0
 public virtual async Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await _productInventoryProvider.GetInventoryAsync(product, productSku, storeId));
 }
Esempio n. 24
0
 public virtual Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(Task.FromResult(productSku.Inventory));
 }
Esempio n. 25
0
 public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, int quantity, bool increaseSold)
 {
     return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, quantity, increaseSold));
 }
Esempio n. 26
0
        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
            });
        }
Esempio n. 27
0
 public virtual Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     return(Task.FromResult(productSku.TryReduceInventory(quantity)));
 }
Esempio n. 28
0
        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));
        }