public final class SetAttribute extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
withUpdateableProduct(client(), product -> { //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 SetAttribute moneyUpdate = SetAttribute.ofVariantId(MASTER_VARIANT_ID, moneyAttribute, newValueForMoney); final SetAttribute localizedEnumUpdate = SetAttribute.ofVariantId(MASTER_VARIANT_ID, 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); final SetAttribute unsetAction = SetAttribute.ofUnsetAttributeForVariantId(MASTER_VARIANT_ID, moneyAttribute); final Product productWithoutMoney = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, unsetAction)); assertThat(productWithoutMoney.getMasterData().getStaged().getMasterVariant().findAttribute(moneyAttribute)).isEmpty(); return productWithoutMoney; });
See the test code.
By SKU (attention, SKU is optional field in a variant):
withUpdateableProduct(client(), product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); //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 SetAttribute moneyUpdate = SetAttribute.ofSku(sku, moneyAttribute, newValueForMoney); final SetAttribute localizedEnumUpdate = SetAttribute.ofSku(sku, 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); final SetAttribute unsetAction = SetAttribute.ofUnsetAttributeForSku(sku, moneyAttribute); final Product productWithoutMoney = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, unsetAction)); assertThat(productWithoutMoney.getMasterData().getStaged().getMasterVariant().findAttribute(moneyAttribute)).isEmpty(); return productWithoutMoney; });
See the test code.
SetAttributeInAllVariants
Modifier and Type | Method and Description |
---|---|
String |
getName() |
String |
getSku() |
com.fasterxml.jackson.databind.JsonNode |
getValue() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static SetAttribute |
of(Integer variantId,
AttributeDraft attribute)
Action to add/change a custom attribute.
|
static SetAttribute |
of(Integer variantId,
AttributeDraft attribute,
Boolean staged) |
static <T> SetAttribute |
of(Integer variantId,
NamedAttributeAccess<T> setter,
T value)
Action to add/change a custom attribute.
|
static <T> SetAttribute |
of(Integer variantId,
NamedAttributeAccess<T> setter,
T value,
Boolean staged) |
static SetAttribute |
of(Integer variantId,
String name,
com.fasterxml.jackson.databind.JsonNode value)
Action to add/remove/change a custom attribute.
|
static SetAttribute |
of(Integer variantId,
String name,
com.fasterxml.jackson.databind.JsonNode value,
Boolean staged) |
static SetAttribute |
ofSku(String sku,
AttributeDraft attribute)
Action to add/change a custom attribute.
|
static SetAttribute |
ofSku(String sku,
AttributeDraft attribute,
Boolean staged) |
static <T> SetAttribute |
ofSku(String sku,
NamedAttributeAccess<T> setter,
T value)
Action to add/change a custom attribute.
|
static <T> SetAttribute |
ofSku(String sku,
NamedAttributeAccess<T> setter,
T value,
Boolean staged) |
static SetAttribute |
ofSku(String sku,
String name,
com.fasterxml.jackson.databind.JsonNode value)
Action to add/remove/change a custom attribute.
|
static SetAttribute |
ofSku(String sku,
String name,
com.fasterxml.jackson.databind.JsonNode value,
Boolean staged) |
static SetAttribute |
ofSku(String sku,
String name,
Object value)
Action to add/remove/change a custom attribute.
|
static SetAttribute |
ofSku(String sku,
String name,
Object value,
Boolean staged) |
static <T> SetAttribute |
ofUnsetAttribute(Integer variantId,
NamedAttributeAccess<T> NamedAttributeAccess)
Action to remove a custom attribute.
|
static <T> SetAttribute |
ofUnsetAttribute(Integer variantId,
NamedAttributeAccess<T> NamedAttributeAccess,
Boolean staged) |
static SetAttribute |
ofUnsetAttribute(Integer variantId,
String name)
Action to remove a custom attribute.
|
static SetAttribute |
ofUnsetAttribute(Integer variantId,
String name,
Boolean staged) |
static <T> SetAttribute |
ofUnsetAttributeForSku(String sku,
NamedAttributeAccess<T> NamedAttributeAccess)
Action to remove a custom attribute.
|
static <T> SetAttribute |
ofUnsetAttributeForSku(String sku,
NamedAttributeAccess<T> NamedAttributeAccess,
Boolean staged) |
static SetAttribute |
ofUnsetAttributeForSku(String sku,
String name)
Action to remove a custom attribute.
|
static SetAttribute |
ofUnsetAttributeForSku(String sku,
String name,
Boolean staged) |
static <T> SetAttribute |
ofUnsetAttributeForVariantId(Integer variantId,
NamedAttributeAccess<T> NamedAttributeAccess)
Action to remove a custom attribute.
|
static <T> SetAttribute |
ofUnsetAttributeForVariantId(Integer variantId,
NamedAttributeAccess<T> NamedAttributeAccess,
Boolean staged) |
static SetAttribute |
ofUnsetAttributeForVariantId(Integer variantId,
String name)
Action to remove a custom attribute.
|
static SetAttribute |
ofUnsetAttributeForVariantId(Integer variantId,
String name,
Boolean staged) |
static SetAttribute |
ofVariantId(Integer variantId,
AttributeDraft attribute)
Action to add/change a custom attribute.
|
static SetAttribute |
ofVariantId(Integer variantId,
AttributeDraft attribute,
Boolean staged) |
static <T> SetAttribute |
ofVariantId(Integer variantId,
NamedAttributeAccess<T> setter,
T value)
Action to add/change a custom attribute.
|
static <T> SetAttribute |
ofVariantId(Integer variantId,
NamedAttributeAccess<T> setter,
T value,
Boolean staged) |
static SetAttribute |
ofVariantId(Integer variantId,
String name,
com.fasterxml.jackson.databind.JsonNode value)
Action to add/remove/change a custom attribute.
|
static SetAttribute |
ofVariantId(Integer variantId,
String name,
com.fasterxml.jackson.databind.JsonNode value,
Boolean staged) |
static SetAttribute |
ofVariantId(Integer variantId,
String name,
Object value)
Action to add/remove/change a custom attribute.
|
static SetAttribute |
ofVariantId(Integer variantId,
String name,
Object value,
Boolean staged) |
getAction
public String getName()
@Nullable public com.fasterxml.jackson.databind.JsonNode getValue()
public static SetAttribute of(Integer variantId, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value)
variantId
- the variant the attribute value should be set or unsetname
- 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 SetAttribute of(Integer variantId, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value, @Nullable Boolean staged)
public static SetAttribute ofVariantId(Integer variantId, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value)
variantId
- the variant the attribute value should be set or unsetname
- 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 SetAttribute ofVariantId(Integer variantId, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value, @Nullable Boolean staged)
public static SetAttribute ofVariantId(Integer variantId, String name, @Nullable Object value)
variantId
- the variant the attribute value should be set or unsetname
- 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 SetAttribute ofVariantId(Integer variantId, String name, @Nullable Object value, @Nullable Boolean staged)
public static SetAttribute ofSku(String sku, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value)
sku
- 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 SetAttribute ofSku(String sku, String name, @Nullable com.fasterxml.jackson.databind.JsonNode value, @Nullable Boolean staged)
public static SetAttribute ofSku(String sku, String name, @Nullable Object value)
sku
- 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 SetAttribute ofSku(String sku, String name, @Nullable Object value, @Nullable Boolean staged)
public static SetAttribute ofUnsetAttribute(Integer variantId, String name)
variantId
- the variant the attribute value should be unsetname
- the name of the attribute, consult the product type to find the namepublic static SetAttribute ofUnsetAttribute(Integer variantId, String name, @Nullable Boolean staged)
public static SetAttribute ofUnsetAttributeForVariantId(Integer variantId, String name)
variantId
- the variant the attribute value should be unsetname
- the name of the attribute, consult the product type to find the namepublic static SetAttribute ofUnsetAttributeForVariantId(Integer variantId, String name, @Nullable Boolean staged)
public static SetAttribute ofUnsetAttributeForSku(String sku, String name)
sku
- name
- the name of the attribute, consult the product type to find the namepublic static SetAttribute ofUnsetAttributeForSku(String sku, String name, @Nullable Boolean staged)
public static <T> SetAttribute ofUnsetAttribute(Integer variantId, NamedAttributeAccess<T> NamedAttributeAccess)
T
- type of the attributevariantId
- the variant the attribute value should be unsetNamedAttributeAccess
- object containing the name of the attributepublic static <T> SetAttribute ofUnsetAttribute(Integer variantId, NamedAttributeAccess<T> NamedAttributeAccess, @Nullable Boolean staged)
public static <T> SetAttribute ofUnsetAttributeForVariantId(Integer variantId, NamedAttributeAccess<T> NamedAttributeAccess)
T
- type of the attributevariantId
- the variant the attribute value should be unsetNamedAttributeAccess
- object containing the name of the attributepublic static <T> SetAttribute ofUnsetAttributeForVariantId(Integer variantId, NamedAttributeAccess<T> NamedAttributeAccess, @Nullable Boolean staged)
public static <T> SetAttribute ofUnsetAttributeForSku(String sku, NamedAttributeAccess<T> NamedAttributeAccess)
T
- type of the attributesku
- NamedAttributeAccess
- object containing the name of the attributepublic static <T> SetAttribute ofUnsetAttributeForSku(String sku, NamedAttributeAccess<T> NamedAttributeAccess, @Nullable Boolean staged)
public static SetAttribute of(Integer variantId, AttributeDraft attribute)
variantId
- the variant the attribute value should be set or unsetattribute
- the name and the value of the attribute to updatepublic static SetAttribute of(Integer variantId, AttributeDraft attribute, @Nullable Boolean staged)
public static SetAttribute ofVariantId(Integer variantId, AttributeDraft attribute)
variantId
- the variant the attribute value should be set or unsetattribute
- the name and the value of the attribute to updatepublic static SetAttribute ofVariantId(Integer variantId, AttributeDraft attribute, @Nullable Boolean staged)
public static SetAttribute ofSku(String sku, AttributeDraft attribute)
sku
- attribute
- the name and the value of the attribute to updatepublic static SetAttribute ofSku(String sku, AttributeDraft attribute, @Nullable Boolean staged)
public static <T> SetAttribute of(Integer variantId, NamedAttributeAccess<T> setter, T value)
T
- type of the attributevariantId
- the variant the attribute value should be set or unsetsetter
- the serializer of the attributevalue
- the value to setpublic static <T> SetAttribute of(Integer variantId, NamedAttributeAccess<T> setter, T value, @Nullable Boolean staged)
public static <T> SetAttribute ofVariantId(Integer variantId, NamedAttributeAccess<T> setter, T value)
T
- type of the attributevariantId
- the variant the attribute value should be set or unsetsetter
- the serializer of the attributevalue
- the value to setpublic static <T> SetAttribute ofVariantId(Integer variantId, NamedAttributeAccess<T> setter, T value, @Nullable Boolean staged)
public static <T> SetAttribute ofSku(String sku, NamedAttributeAccess<T> setter, T value)
T
- type of the attributesku
- setter
- the serializer of the attributevalue
- the value to setpublic static <T> SetAttribute ofSku(String sku, NamedAttributeAccess<T> setter, T value, @Nullable Boolean staged)