public final class ChangeAssetOrder extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final List<Asset> originalAssets = product.getMasterData().getStaged().getMasterVariant().getAssets(); final List<String> newAssetOrder = new LinkedList<>(originalAssets.stream().map(Asset::getId).collect(toList())); Collections.reverse(newAssetOrder); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetOrder.ofVariantId(MASTER_VARIANT_ID, newAssetOrder)); final Product updatedProduct = client().executeBlocking(cmd); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).extracting(Asset::getId).isEqualTo(newAssetOrder); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
By SKU (attention, SKU is optional field in a variant):
withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final List<Asset> originalAssets = masterVariant.getAssets(); final List<String> newAssetOrder = new LinkedList<>(originalAssets.stream().map(Asset::getId).collect(toList())); Collections.reverse(newAssetOrder); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetOrder.ofSku(masterVariant.getSku(), newAssetOrder)); final Product updatedProduct = client().executeBlocking(cmd); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).extracting(Asset::getId).isEqualTo(newAssetOrder); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
Modifier and Type | Method and Description |
---|---|
List<String> |
getAssetOrder() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static ChangeAssetOrder |
ofSku(String sku,
List<String> assetOrder) |
static ChangeAssetOrder |
ofSku(String sku,
List<String> assetOrder,
Boolean staged) |
static ChangeAssetOrder |
ofVariantId(Integer variantId,
List<String> assetOrder) |
static ChangeAssetOrder |
ofVariantId(Integer variantId,
List<String> assetOrder,
Boolean staged) |
getAction
public static ChangeAssetOrder ofVariantId(Integer variantId, List<String> assetOrder)
public static ChangeAssetOrder ofVariantId(Integer variantId, List<String> assetOrder, @Nullable Boolean staged)
public static ChangeAssetOrder ofSku(String sku, List<String> assetOrder)
public static ChangeAssetOrder ofSku(String sku, List<String> assetOrder, @Nullable Boolean staged)