public final class SetProductVariantKey extends UpdateActionImpl<T>
ProductVariant
, for Product
s use SetKey
.
See also ProductUpdateCommand.
Use the variantId to select the variant
final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndVariantId(key, variantId)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getKey()).isNotEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); });
See the test code.
final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndSku(key, sku)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getKey()).isNotEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); });
See the test code.
ProductVariant.getKey()
Modifier and Type | Method and Description |
---|---|
String |
getKey() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static SetProductVariantKey |
ofKeyAndSku(String key,
String sku) |
static SetProductVariantKey |
ofKeyAndSku(String key,
String sku,
Boolean staged) |
static SetProductVariantKey |
ofKeyAndVariantId(String key,
Integer variantId) |
static SetProductVariantKey |
ofKeyAndVariantId(String key,
Integer variantId,
Boolean staged) |
getAction
public static SetProductVariantKey ofKeyAndVariantId(@Nullable String key, @Nonnull Integer variantId)
public static SetProductVariantKey ofKeyAndVariantId(@Nullable String key, @Nonnull Integer variantId, @Nullable Boolean staged)
public static SetProductVariantKey ofKeyAndSku(@Nullable String key, @Nonnull String sku)
public static SetProductVariantKey ofKeyAndSku(@Nullable String key, @Nonnull String sku, @Nullable Boolean staged)