public final class ChangeAssetName extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofVariantId(masterVariant.getId(), assetId, newName)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); 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 LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofSku(masterVariant.getSku(), assetId, newName)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
getAction
public String getAssetId()
public String getAssetKey()
public LocalizedString getName()
public static ChangeAssetName ofVariantId(Integer variantId, String assetId, LocalizedString name)
public static ChangeAssetName ofVariantId(Integer variantId, String assetId, LocalizedString name, @Nullable Boolean staged)
public static ChangeAssetName ofSku(String sku, String assetId, LocalizedString name)
public static ChangeAssetName ofSku(String sku, String assetId, LocalizedString name, @Nullable Boolean staged)
public static ChangeAssetName ofAssetKeyAndVariantId(Integer variantId, String assetKey, LocalizedString name)
public static ChangeAssetName ofAssetKeyAndVariantId(Integer variantId, String assetKey, LocalizedString name, @Nullable Boolean staged)
public static ChangeAssetName ofAssetKeyAndSku(String sku, String assetKey, LocalizedString name)
public static ChangeAssetName ofAssetKeyAndSku(String sku, String assetKey, LocalizedString name, @Nullable Boolean staged)