/** * Action to add/remove/change a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @param value embedded in an optional the new value of the attribute or an empty Optional to remove the value from the attribute * @return update action */ public static SetAttributeInAllVariants of(final String name, final JsonNode value) { return of(name, value, null); }
/** * Action to add/remove/change a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @param value embedded in an optional the new value of the attribute or an empty Optional to remove the value from the attribute * @return update action */ public static SetAttributeInAllVariants of(final String name, final JsonNode value) { return new SetAttributeInAllVariants(name, value); }
/** * Action to remove a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @return update action */ public static SetAttributeInAllVariants ofUnsetAttribute(final String name) { return ofUnsetAttribute(name, null); }
@Test public void setAttributeInAllVariants() throws Exception { 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; }); }
/** * Action to add/change a custom attribute. * * @param setter the serializer of the attribute * @param value the value to set * @param <T> type of the attribute * @return update action */ public static <T> SetAttributeInAllVariants of(final NamedAttributeAccess<T> setter, final T value) { return of(setter, value, null); }
/** * Action to add/remove/change a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @param value embedded in an optional the new value of the attribute or an empty Optional to remove the value from the attribute * @param productUpdateScope the scope where the attribute should be updated * @return update action */ public static SetAttributeInAllVariants of(final String name, final Optional<JsonNode> value, final ProductUpdateScope productUpdateScope) { return new SetAttributeInAllVariants(name, value, productUpdateScope); }
/** * Action to remove a custom attribute. * * @param NamedAttributeAccess object containing the name of the attribute * @param <T> type of the attribute * @return update action */ public static <T> SetAttributeInAllVariants ofUnsetAttribute(final NamedAttributeAccess<T> NamedAttributeAccess) { return ofUnsetAttribute(NamedAttributeAccess, null); }
/** * Action to remove a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @return update action */ public static SetAttributeInAllVariants ofUnsetAttribute(final String name) { return of(name, null); }
public static SetAttributeInAllVariants of(final String name, final JsonNode value, @Nullable final Boolean staged) { return new SetAttributeInAllVariants(name, value, staged); }
/** * Action to remove a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @return update action */ public static SetAttributeInAllVariants ofUnsetAttribute(final String name) { return ofUnsetAttribute(name, null); }
/** * Action to add/change a custom attribute. * * @param attribute the name and the value of the attribute to update * @return update action */ public static SetAttributeInAllVariants of(final AttributeDraft attribute) { return of(attribute, null); }
public static SetAttributeInAllVariants of(final String name, final JsonNode value, @Nullable final Boolean staged) { return new SetAttributeInAllVariants(name, value, staged); }
/** * Action to remove a custom attribute. * * @param NamedAttributeAccess object containing the name of the attribute * @param <T> type of the attribute * @return update action */ public static <T> SetAttributeInAllVariants ofUnsetAttribute(final NamedAttributeAccess<T> NamedAttributeAccess) { return ofUnsetAttribute(NamedAttributeAccess, null); }
/** * Action to add/change a custom attribute. * * @param setter the serializer of the attribute * @param value the value to set * @param <T> type of the attribute * @return update action */ public static <T> SetAttributeInAllVariants of(final NamedAttributeAccess<T> setter, final T value) { return of(setter, value, null); }
@Test @SuppressWarnings({"varargs", "unchecked"}) public void ofUnsetAttribute() { assertThat(product.getMasterData().getStaged().getAllVariants()) .extracting(variant -> variant.getAttribute(ATTR_NAME).getValueAsLocalizedEnumValueSet()) .as("product attributes present") .contains(new HashSet<>(ALL_ATTRIBUTE_VALUES)); final UpdateAction<Product> action = SetAttributeInAllVariants.ofUnsetAttribute("ProductFlags"); product = client().executeBlocking(ProductUpdateCommand.of(product, action)); assertThat(product.getMasterData().getStaged().getAllVariants()) .extracting(variant -> variant.hasAttribute(ATTR_NAME)) .as("attribute is deleted") .containsExactly(false, false); }
/** * Action to add/remove/change a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @param value embedded in an optional the new value of the attribute or an empty Optional to remove the value from the attribute * @return update action */ public static SetAttributeInAllVariants of(final String name, final JsonNode value) { return of(name, value, null); }
/** * Action to add/change a custom attribute. * * @param attribute the name and the value of the attribute to update * @return update action */ public static SetAttributeInAllVariants of(final AttributeDraft attribute) { return of(attribute, null); }
/** * Action to remove a custom attribute. * * @param name the name of the attribute, consult the product type to find the name * @param productUpdateScope the scope where the attribute should be updated * @return update action */ public static SetAttributeInAllVariants ofUnsetAttribute(final String name, final ProductUpdateScope productUpdateScope) { return of(name, Optional.<JsonNode>empty(), productUpdateScope); }
public static SetAttributeInAllVariants ofUnsetAttribute(final String name, @Nullable final Boolean staged) { return of(name, null, staged); }
public static SetAttributeInAllVariants ofUnsetAttribute(final String name, @Nullable final Boolean staged) { return of(name, null, staged); }