public final class MoveImageToPosition extends UpdateActionImpl<T>
See also ProductUpdateCommand.
withProductWithImages(client(), IMAGE_URLS, (Product product) -> {
final List<String> oldImageOrderUrls = product.getMasterData().getStaged().getMasterVariant().getImages()
.stream()
.map(image -> image.getUrl())
.collect(toList());
assertThat(oldImageOrderUrls).containsExactlyElementsOf(IMAGE_URLS);
assertThat(product.getMasterData().hasStagedChanges()).isFalse();
final Integer position = 0;
final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant();
final List<Image> images = masterVariant.getImages();
final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, MoveImageToPosition.ofImageUrlAndSku(images.get(1).getUrl(), masterVariant.getSku(), position));
final Product updatedProduct = client().executeBlocking(cmd);
final List<String> urls = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()
.stream()
.map(image -> image.getUrl())
.collect(toList());
assertThat(urls).containsExactly(URL_2, URL_1, URL_3);
assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue();
return updatedProduct;
});
See the test code.
withProductWithImages(client(), IMAGE_URLS, (Product product) -> {
final List<String> oldImageOrderUrls = product.getMasterData().getStaged().getMasterVariant().getImages()
.stream()
.map(image -> image.getUrl())
.collect(toList());
assertThat(oldImageOrderUrls).containsExactlyElementsOf(IMAGE_URLS);
assertThat(product.getMasterData().hasStagedChanges()).isFalse();
final Integer position = 0;
final List<Image> images = product.getMasterData().getStaged().getMasterVariant().getImages();
final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, MoveImageToPosition.ofImageUrlAndVariantId(images.get(1).getUrl(), MASTER_VARIANT_ID, position));
final Product updatedProduct = client().executeBlocking(cmd);
final List<String> urls = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()
.stream()
.map(image -> image.getUrl())
.collect(toList());
assertThat(urls).containsExactly(URL_2, URL_1, URL_3);
assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue();
return updatedProduct;
});
See the test code.
ProductVariant.getImages()
Modifier and Type | Method and Description |
---|---|
String |
getImageUrl() |
Integer |
getPosition() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static MoveImageToPosition |
ofImageUrlAndSku(String imageUrl,
String sku,
Integer position) |
static MoveImageToPosition |
ofImageUrlAndSku(String imageUrl,
String sku,
Integer position,
Boolean staged) |
static MoveImageToPosition |
ofImageUrlAndVariantId(String imageUrl,
Integer variantId,
Integer position) |
static MoveImageToPosition |
ofImageUrlAndVariantId(String imageUrl,
Integer variantId,
Integer position,
Boolean staged) |
getAction
public static MoveImageToPosition ofImageUrlAndVariantId(String imageUrl, Integer variantId, Integer position)
public static MoveImageToPosition ofImageUrlAndVariantId(String imageUrl, Integer variantId, Integer position, @Nullable Boolean staged)
public static MoveImageToPosition ofImageUrlAndSku(String imageUrl, String sku, Integer position)
public static MoveImageToPosition ofImageUrlAndSku(String imageUrl, String sku, Integer position, @Nullable Boolean staged)
public String getImageUrl()
public Integer getPosition()