public async Task UpdateProductTypeChangeLabelOfEnumValue() { var newLabel = $"enum-Label-{TestingUtility.RandomInt()}"; await WithUpdateableProductType(client, async productType => { Assert.NotEmpty(productType.Attributes); var enumAttributeDefinition = productType.Attributes.FirstOrDefault(attribute => attribute.Type.GetType() == typeof(EnumAttributeType)); Assert.NotNull(enumAttributeDefinition); var enumAttribute = enumAttributeDefinition.Type as EnumAttributeType; Assert.NotNull(enumAttribute); Assert.NotEmpty(enumAttribute.Values); var newEnumValue = new PlainEnumValue { Key = enumAttribute.Values[0].Key, Label = newLabel }; var updateActions = new List <UpdateAction <ProductType> >(); var changeEnumValueLabelAction = new ChangeEnumValueLabelUpdateAction { AttributeName = enumAttributeDefinition.Name, NewValue = newEnumValue }; updateActions.Add(changeEnumValueLabelAction); var updatedType = await client .ExecuteAsync(new UpdateByIdCommand <ProductType>(productType, updateActions)); var updatedEnumAttribute = updatedType.Attributes.FirstOrDefault(attribute => attribute.Type.GetType() == typeof(EnumAttributeType))?.Type as EnumAttributeType; Assert.NotNull(updatedEnumAttribute); Assert.Contains(updatedEnumAttribute.Values, value => value.Key == newEnumValue.Key && value.Label == newEnumValue.Label); return(updatedType); }); }
public async Task UpdateProductTypeAddPlainEnumValue() { var rand = TestingUtility.RandomInt(); var newPlainEnumValue = new PlainEnumValue { Key = $"enum-key-{rand}", Label = $"enum-label-{rand}" }; await WithUpdateableProductType(client, async productType => { Assert.NotEmpty(productType.Attributes); var enumAttribute = productType.Attributes.FirstOrDefault(attribute => attribute.Type.GetType() == typeof(EnumAttributeType)); Assert.NotNull(enumAttribute); var updateActions = new List <UpdateAction <ProductType> >(); var addPlainEnumValueToAttributeAction = new AddPlainEnumValueToAttributeDefinitionUpdateAction { AttributeName = enumAttribute.Name, Value = newPlainEnumValue }; updateActions.Add(addPlainEnumValueToAttributeAction); var updatedType = await client .ExecuteAsync(new UpdateByIdCommand <ProductType>(productType, updateActions)); var updatedEnumAttribute = updatedType.Attributes.FirstOrDefault(attribute => attribute.Type.GetType() == typeof(EnumAttributeType))?.Type as EnumAttributeType; Assert.NotNull(updatedEnumAttribute); Assert.Contains(updatedEnumAttribute.Values, value => value.Key == newPlainEnumValue.Key && value.Label == newPlainEnumValue.Label); return(updatedType); }); }
/// <summary> /// Constructor. /// </summary> /// <param name="attributeName">The name of the attribute definition to update.</param> /// <param name="value">Value</param> public AddPlainEnumValueAction(string attributeName, PlainEnumValue value) { this.Action = "addPlainEnumValue"; this.AttributeName = attributeName; this.Value = value; }
private Product CreateOrRetrievePricedProduct(string key, List <PriceDraft> prices, Money moneyAttrValue = null, double?numberAttrValue = null, PlainEnumValue enumAttrValue = null) { var product = CreateOrRetrieveByKey <Product, ProductDraft>(client, key, new ProductDraft(), draft => { var productDraft = DefaultProductDraftWithProductType(draft, AvailableProductType); productDraft.Key = key; productDraft.MasterVariant.Sku = key; productDraft.Name = new LocalizedString { { "en", key } }; productDraft.MasterVariant.Prices = prices; if (enumAttrValue != null && numberAttrValue.HasValue) { productDraft.MasterVariant.Attributes = new List <Attribute> { new NumberAttribute { Name = "number-attribute-name", Value = numberAttrValue.Value }, new MoneyAttribute { Name = "money-attribute-name", Value = moneyAttrValue }, new EnumAttribute { Name = "enum-attribute-name", Value = enumAttrValue }, new ReferenceAttribute { Name = "reference-attribute-name", Value = new Reference { Id = AvailableProductType.Id, TypeId = ReferenceTypeId.ProductType } } }; } return(productDraft); }); 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); }
/// <summary> /// Constructor. /// </summary> /// <param name="attributeName">The name of the attribute definition to update.</param> /// <param name="newValue">New Value</param> public ChangePlainEnumValueLabelAction(string attributeName, PlainEnumValue newValue) { this.Action = "changePlainEnumValueLabel"; this.AttributeName = attributeName; this.NewValue = newValue; }