public final class AddExternalImage extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
By SKU (attention, SKU is optional field in a variant):
withUpdateableProduct(client(), (Product product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getImages()).hasSize(0); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(masterVariant.getSku(), image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
ProductVariant.getImages()
,
RemoveImage
Modifier and Type | Method and Description |
---|---|
Image |
getImage() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static AddExternalImage |
of(Image image,
Integer variantId) |
static AddExternalImage |
ofSku(String sku,
Image image) |
static AddExternalImage |
ofSku(String sku,
Image image,
Boolean staged) |
static AddExternalImage |
ofVariantId(Integer variantId,
Image image) |
static AddExternalImage |
ofVariantId(Integer variantId,
Image image,
Boolean staged) |
getAction
public static AddExternalImage of(Image image, Integer variantId)
public static AddExternalImage ofVariantId(Integer variantId, Image image)
public static AddExternalImage ofVariantId(Integer variantId, Image image, @Nullable Boolean staged)
public static AddExternalImage ofSku(String sku, Image image)
public static AddExternalImage ofSku(String sku, Image image, @Nullable Boolean staged)
public Image getImage()