public final class SetAttributeInAllVariants extends UpdateActionImpl<T>
See also ProductUpdateCommand.
withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); //the setter contains the name and a JSON mapper, declare it only one time in your project per attribute //example for MonetaryAmount attribute final String moneyAttributeName = MONEY_ATTRIBUTE_NAME; final NamedAttributeAccess<MonetaryAmount> moneyAttribute = AttributeAccess.ofMoney().ofName(moneyAttributeName); final MonetaryAmount newValueForMoney = EURO_10; //example for LocalizedEnumValue attribute final NamedAttributeAccess<LocalizedEnumValue> colorAttribute = Colors.ATTRIBUTE; final LocalizedEnumValue oldValueForColor = Colors.GREEN; final LocalizedEnumValue newValueForColor = Colors.RED; assertThat(product.getMasterData().getStaged().getMasterVariant().findAttribute(moneyAttribute)).isEmpty(); assertThat(product.getMasterData().getStaged().getMasterVariant().findAttribute(colorAttribute)).contains(oldValueForColor); final SetAttributeInAllVariants moneyUpdate = SetAttributeInAllVariants.of(moneyAttribute, newValueForMoney); final SetAttributeInAllVariants localizedEnumUpdate = SetAttributeInAllVariants.of(colorAttribute, newValueForColor); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList(moneyUpdate, localizedEnumUpdate))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().findAttribute(moneyAttribute)).contains(newValueForMoney); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().findAttribute(colorAttribute)).contains(newValueForColor); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); final SetAttributeInAllVariants unsetAction = SetAttributeInAllVariants.ofUnsetAttribute(moneyAttribute); final Product productWithoutMoney = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, unsetAction)); assertThat(productWithoutMoney.getMasterData().getStaged().getMasterVariant().findAttribute(moneyAttribute)).isEmpty(); return productWithoutMoney; });
See the test code.
SetAttribute
Modifier and Type | Method and Description |
---|---|
String |
getName() |
com.fasterxml.jackson.databind.JsonNode |
getValue() |
Boolean |
isStaged() |
static SetAttributeInAllVariants |
of(AttributeDraft attribute)
Action to add/change a custom attribute.
|
static SetAttributeInAllVariants |
of(AttributeDraft attribute,
Boolean staged) |
static <T> SetAttributeInAllVariants |
of(NamedAttributeAccess<T> setter,
T value)
Action to add/change a custom attribute.
|
static <T> SetAttributeInAllVariants |
of(NamedAttributeAccess<T> setter,
T value,
Boolean staged) |
static SetAttributeInAllVariants |
of(String name,
com.fasterxml.jackson.databind.JsonNode value)
Action to add/remove/change a custom attribute.
|
static SetAttributeInAllVariants |
of(String name,
com.fasterxml.jackson.databind.JsonNode value,
Boolean staged) |
static <T> SetAttributeInAllVariants |
ofUnsetAttribute(NamedAttributeAccess<T> NamedAttributeAccess)
Action to remove a custom attribute.
|
static <T> SetAttributeInAllVariants |
ofUnsetAttribute(NamedAttributeAccess<T> NamedAttributeAccess,
Boolean staged) |
static SetAttributeInAllVariants |
ofUnsetAttribute(String name)
Action to remove a custom attribute.
|
static SetAttributeInAllVariants |
ofUnsetAttribute(String name,
Boolean staged) |
getAction
public String getName()
@Nullable public com.fasterxml.jackson.databind.JsonNode getValue()
public static SetAttributeInAllVariants of(String name, com.fasterxml.jackson.databind.JsonNode value)
name
- the name of the attribute, consult the product type to find the namevalue
- embedded in an optional the new value of the attribute or an empty Optional to remove the value from the attributepublic static SetAttributeInAllVariants of(String name, com.fasterxml.jackson.databind.JsonNode value, @Nullable Boolean staged)
public static SetAttributeInAllVariants ofUnsetAttribute(String name)
name
- the name of the attribute, consult the product type to find the namepublic static SetAttributeInAllVariants ofUnsetAttribute(String name, @Nullable Boolean staged)
public static <T> SetAttributeInAllVariants ofUnsetAttribute(NamedAttributeAccess<T> NamedAttributeAccess)
T
- type of the attributeNamedAttributeAccess
- object containing the name of the attributepublic static <T> SetAttributeInAllVariants ofUnsetAttribute(NamedAttributeAccess<T> NamedAttributeAccess, @Nullable Boolean staged)
public static SetAttributeInAllVariants of(AttributeDraft attribute)
attribute
- the name and the value of the attribute to updatepublic static SetAttributeInAllVariants of(AttributeDraft attribute, @Nullable Boolean staged)
public static <T> SetAttributeInAllVariants of(NamedAttributeAccess<T> setter, T value)
T
- type of the attributesetter
- the serializer of the attributevalue
- the value to setpublic static <T> SetAttributeInAllVariants of(NamedAttributeAccess<T> setter, T value, @Nullable Boolean staged)