public async Task TestProductVariantAvailabilityDeserialize() { dynamic data = JsonConvert.DeserializeObject("{ \"isOnStock\": true, \"restockableInDays\": 3, \"availableQuantity\": 3, \"channels\": { \"foo\": { \"isOnStock\": true, \"restockableInDays\": 3, \"availableQuantity\": 4 } } }"); var availability = new ProductVariantAvailability(data); Assert.IsInstanceOf <ProductVariantAvailability>(availability.Channels["foo"]); Assert.AreEqual(4, availability.Channels["foo"].AvailableQuantity); }
private InventoryEntry CreateOrRetrieveInventoryEntry(Product product, ProductVariantAvailability variantAvailability, Channel supplyChannel = null) { var inventoryEntrySku = $"{KeyPrefix}_InventoryEntryOfProduct_{product.Key}"; var inventoryEntry = CreateOrRetrieveBySku(client, inventoryEntrySku, new InventoryEntryDraft(), draft => { var inventoryEntryDraft = DefaultInventoryEntryDraftWithSku(draft, inventoryEntrySku); inventoryEntryDraft.Sku = product.MasterData.Staged.MasterVariant.Sku; inventoryEntryDraft.SupplyChannel = supplyChannel?.ToReference(); inventoryEntryDraft.QuantityOnStock = variantAvailability.AvailableQuantity; inventoryEntryDraft.RestockableInDays = variantAvailability.RestockableInDays; return(inventoryEntryDraft); }); return(inventoryEntry); }
private Product CreateCustomizedProduct(string sku = null, string productKey = null, string productVariantKey = null, TaxCategory taxCategory = null, List <PriceDraft> prices = null, State state = null, List <Attribute> attributes = null, ProductVariantAvailability productVariantAvailability = null, Channel supplyChannel = null, Dictionary <string, List <SearchKeywords> > searchKeywords = null, LocalizedString productName = null) { var productDraft = this.productFixture.GetProductDraft(); productDraft.MasterVariant.Sku = sku; productDraft.Key = productKey; productDraft.MasterVariant.Key = productVariantKey; productDraft.MasterVariant.Prices = prices; productDraft.MasterVariant.Attributes = attributes; productDraft.TaxCategory = taxCategory?.ToReference(); productDraft.State = state?.ToReference(); productDraft.SearchKeywords = searchKeywords; productDraft.Name = productName ?? new LocalizedString() { { "en", TestingUtility.RandomString(10) } }; var product = this.productFixture.CreateProduct(productDraft); if (productVariantAvailability != null) { // then add inventory it for this product, and get product again var inventoryDraft = new InventoryEntryDraft { Sku = product.MasterData.Staged.MasterVariant.Sku, QuantityOnStock = productVariantAvailability.AvailableQuantity, SupplyChannel = supplyChannel?.ToReference(), RestockableInDays = productVariantAvailability.RestockableInDays }; this.CreateInventoryEntry(inventoryDraft); product = this.productFixture.GetProductById(product.Id); } this.productFixture.ProductsToDelete.Add(product); return(product); }
private void CreateProductsWithPrices() { var channel1 = AvailableChannels[0]; var channel2 = AvailableChannels[1]; var channel3 = AvailableChannels[2]; //Product30 var product30Prices = new List <PriceDraft> { TestingUtility.Euro30, TestingUtility.EuroScoped40 }; var product30EnumValue = new PlainEnumValue { Key = "enum-key-1", Label = "enum-label-1" }; var product30Availability = new ProductVariantAvailability { AvailableQuantity = 0 }; var product30 = CreateOrRetrievePricedProduct(KeyProductWithPrice30, product30Prices, TestingUtility.Money30, 30, product30EnumValue); var product30InChannel2 = CreateOrRetrievePricedProduct(KeyProductWithPrice30InChannel2, product30Prices); var product30InChannel3 = CreateOrRetrievePricedProduct(KeyProductWithPrice30InChannel3, product30Prices); //product50 var product50Prices = new List <PriceDraft> { TestingUtility.Euro50, TestingUtility.EuroScoped60 }; var product50EnumValue = new PlainEnumValue { Key = "enum-key-2", Label = "enum-label-2" }; var product50Availability = new ProductVariantAvailability { AvailableQuantity = 3, RestockableInDays = 3 }; var product50 = CreateOrRetrievePricedProduct(KeyProductWithPrice50, product50Prices, TestingUtility.Money50, 50, product50EnumValue); //product70 var product70Prices = new List <PriceDraft> { TestingUtility.Euro70, TestingUtility.EuroScoped80 }; var product70EnumValue = new PlainEnumValue { Key = "enum-key-3", Label = "enum-label-3" }; var product70Availability = new ProductVariantAvailability { AvailableQuantity = 6, RestockableInDays = 6 }; var product70 = CreateOrRetrievePricedProduct(KeyProductWithPrice70, product70Prices, TestingUtility.Money70, 70, product70EnumValue); //product90WithDiscount var product90WithDiscountPrices = new List <PriceDraft> { TestingUtility.Euro90, TestingUtility.EuroScoped100 }; var product90WithDiscount = CreateOrRetrievePricedProduct(KeyProductWithPrice90WithDiscount, product90WithDiscountPrices); var productDiscount = CreateOrRetrieveProductDiscountOfAbsoluteValue(product90WithDiscount.Id, TestingUtility.DiscountOf5Euro); // Product Available without channel var product30WithoutChannel = CreateOrRetrievePricedProduct(KeyProductWithPrice30WithoutChannel, product30Prices); var product50WithoutChannel = CreateOrRetrievePricedProduct(KeyProductWithPrice50WithoutChannel, product50Prices); var product70WithoutChannel = CreateOrRetrievePricedProduct(KeyProductWithPrice70WithoutChannel, product70Prices); //Creating reviews to product30 CreateOrRetrieveReview(product30, 1, "1"); CreateOrRetrieveReview(product30, 3, "2"); //Creating reviews to product50 CreateOrRetrieveReview(product50, 3, "1"); CreateOrRetrieveReview(product50, 5, "2"); //Creating reviews to product70 CreateOrRetrieveReview(product70, 1, "1"); CreateOrRetrieveReview(product70, 1, "2"); //Inventory CreateOrRetrieveInventoryEntry(product30, product30Availability, channel1); CreateOrRetrieveInventoryEntry(product50, product50Availability, channel1); CreateOrRetrieveInventoryEntry(product70, product70Availability, channel1); CreateOrRetrieveInventoryEntry(product30InChannel2, new ProductVariantAvailability { AvailableQuantity = 2 }, channel2); CreateOrRetrieveInventoryEntry(product30InChannel3, new ProductVariantAvailability { AvailableQuantity = 4 }, channel3); CreateOrRetrieveInventoryEntry(product30WithoutChannel, new ProductVariantAvailability { AvailableQuantity = 0 }, null); CreateOrRetrieveInventoryEntry(product50WithoutChannel, new ProductVariantAvailability { AvailableQuantity = 3 }, null); CreateOrRetrieveInventoryEntry(product70WithoutChannel, new ProductVariantAvailability { AvailableQuantity = 6 }, null); }