public final class RemoveAsset 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 Asset assetToRemove = originalAssets.get(0); final String assetId = assetToRemove.getId(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofVariantId(MASTER_VARIANT_ID, assetId))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).hasSize(originalAssets.size() - 1); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); 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 String assetId = masterVariant.getAssets().get(0).getId(); final String sku = masterVariant.getSku(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofSku(sku, assetId))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
Modifier and Type | Method and Description |
---|---|
String |
getAssetId() |
String |
getAssetKey() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static RemoveAsset |
ofSku(String sku,
String assetId) |
static RemoveAsset |
ofSku(String sku,
String assetId,
Boolean staged) |
static RemoveAsset |
ofSkuWithKey(String sku,
String assetKey) |
static RemoveAsset |
ofSkuWithKey(String sku,
String assetKey,
Boolean staged) |
static RemoveAsset |
ofVariantId(Integer variantId,
String assetId) |
static RemoveAsset |
ofVariantId(Integer variantId,
String assetId,
Boolean staged) |
static RemoveAsset |
ofVariantIdWithKey(Integer variantId,
String assetKey) |
static RemoveAsset |
ofVariantIdWithKey(Integer variantId,
String assetKey,
Boolean staged) |
getAction
public String getAssetId()
public String getAssetKey()
public static RemoveAsset ofVariantId(Integer variantId, String assetId)
public static RemoveAsset ofVariantId(Integer variantId, String assetId, @Nullable Boolean staged)
public static RemoveAsset ofSku(String sku, String assetId)
public static RemoveAsset ofSku(String sku, String assetId, @Nullable Boolean staged)
public static RemoveAsset ofVariantIdWithKey(Integer variantId, String assetKey)
public static RemoveAsset ofVariantIdWithKey(Integer variantId, String assetKey, @Nullable Boolean staged)
public static RemoveAsset ofSkuWithKey(String sku, String assetKey)
public static RemoveAsset ofSkuWithKey(String sku, String assetKey, @Nullable Boolean staged)