/** * Action to add/change a custom attribute. * * @param sku * @param attribute the name and the value of the attribute to update * @return update action */ public static SetAttribute ofSku(final String sku, final AttributeDraft attribute) { return ofSku(sku, attribute, null); }
/** * Action to add/change a custom attribute. * * @param sku * @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> SetAttribute ofSku(final String sku, final NamedAttributeAccess<T> setter, final T value) { return ofSku(sku, setter, value, null); }
/** * Action to add/change a custom attribute. * * @param sku * @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> SetAttribute ofSku(final String sku, final NamedAttributeAccess<T> setter, final T value) { return ofSku(sku, setter, value, null); }
/** * Action to add/change a custom attribute. * * @param sku * @param attribute the name and the value of the attribute to update * @return update action */ public static SetAttribute ofSku(final String sku, final AttributeDraft attribute) { return ofSku(sku, attribute, null); }
/** * Action to add/remove/change a custom attribute. * * @param sku * @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 SetAttribute ofSku(final String sku, final String name, @Nullable final Object value) { return ofSku(sku, name, value, null); }
/** * Action to add/remove/change a custom attribute. * * @param sku * @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 SetAttribute ofSku(final String sku, final String name, @Nullable final JsonNode value) { return ofSku(sku, name, value, null); }
/** * Action to add/remove/change a custom attribute. * * @param sku * @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 SetAttribute ofSku(final String sku, final String name, @Nullable final JsonNode value) { return ofSku(sku, name, value, null); }
/** * Action to add/remove/change a custom attribute. * * @param sku * @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 SetAttribute ofSku(final String sku, final String name, @Nullable final Object value) { return ofSku(sku, name, value, null); }
public static SetAttribute ofUnsetAttributeForSku(final String sku, final String name, @Nullable final Boolean staged) { return ofSku(sku, name, null, staged); }
public static SetAttribute ofUnsetAttributeForSku(final String sku, final String name, @Nullable final Boolean staged) { return ofSku(sku, name, null, staged); }
public static <T> SetAttribute ofSku(final String sku, final NamedAttributeAccess<T> setter, final T value, @Nullable final Boolean staged) { return ofSku(sku, AttributeDraft.of(setter, value), staged); } }
public static <T> SetAttribute ofSku(final String sku, final NamedAttributeAccess<T> setter, final T value, @Nullable final Boolean staged) { return ofSku(sku, AttributeDraft.of(setter, value), staged); } }
public static <T> SetAttribute ofUnsetAttributeForSku(final String sku, final NamedAttributeAccess<T> NamedAttributeAccess, @Nullable final Boolean staged) { return ofSku(sku, NamedAttributeAccess.getName(), null, staged); }
public static <T> SetAttribute ofUnsetAttributeForSku(final String sku, final NamedAttributeAccess<T> NamedAttributeAccess, @Nullable final Boolean staged) { return ofSku(sku, NamedAttributeAccess.getName(), null, staged); }
public static SetAttribute ofSku(final String sku, final AttributeDraft attribute, @Nullable final Boolean staged) { return ofSku(sku, attribute.getName(), attribute.getValue(), staged); }
public static SetAttribute ofSku(final String sku, final AttributeDraft attribute, @Nullable final Boolean staged) { return ofSku(sku, attribute.getName(), attribute.getValue(), staged); }
public void setAttributeWithObjectsWithStaged(final Boolean staged) { withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList( SetAttribute.ofSku(sku, "size", "M", staged), SetAttribute.ofVariantId(MASTER_VARIANT_ID, "color", "red", staged) ))); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getAttribute("size").getValueAsEnumValue()).isEqualTo(EnumValue.of("M", "M")); assertThat(masterVariant.getAttribute("color").getValueAsLocalizedEnumValue().getKey()).isEqualTo("red"); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); }); }
@Test public void setAttributeWithObjects() { withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList( SetAttribute.ofSku(sku, "size", "M"), SetAttribute.ofVariantId(MASTER_VARIANT_ID, "color", "red") ))); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getAttribute("size").getValueAsEnumValue()).isEqualTo(EnumValue.of("M", "M")); assertThat(masterVariant.getAttribute("color").getValueAsLocalizedEnumValue().getKey()).isEqualTo("red"); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); }); }
@Test public void setAttributeBySku() throws Exception { 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; }); }