public final class AddPrice extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, priceDraft))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
By SKU (attention, SKU is optional field in a variant):
final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofSku(sku, priceDraft))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; });
See the test code.
ProductVariant.getPrices()
Modifier and Type | Method and Description |
---|---|
PriceDraft |
getPrice() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static AddPrice |
of(Integer variantId,
PriceDraft price) |
static AddPrice |
ofSku(String sku,
PriceDraft price) |
static AddPrice |
ofSku(String sku,
PriceDraft price,
Boolean staged) |
static AddPrice |
ofVariantId(Integer variantId,
PriceDraft price) |
static AddPrice |
ofVariantId(Integer variantId,
PriceDraft price,
Boolean staged) |
getAction
public PriceDraft getPrice()
public static AddPrice of(Integer variantId, PriceDraft price)
public static AddPrice ofVariantId(Integer variantId, PriceDraft price)
public static AddPrice ofVariantId(Integer variantId, PriceDraft price, @Nullable Boolean staged)
public static AddPrice ofSku(String sku, PriceDraft price)
public static AddPrice ofSku(String sku, PriceDraft price, @Nullable Boolean staged)