public final class SetPrices extends UpdateActionImpl<T>
See also ProductUpdateCommand.
By variant ID (every variant has a variantId):
final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR));
final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE);
final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2);
withUpdateableProduct(client(), product -> {
assertThat(product.getMasterData().hasStagedChanges()).isFalse();
final Product updatedProduct = client()
.executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofVariantId(1, expectedPriceList)));
final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices();
List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList());
assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2);
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(123, EUR));
final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE);
final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2);
withUpdateableProduct(client(), product -> {
assertThat(product.getMasterData().hasStagedChanges()).isFalse();
final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
final Product updatedProduct = client()
.executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofSku(sku, expectedPriceList)));
final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices();
List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList());
assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2);
assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue();
return updatedProduct;
});
See the test code.
ProductVariant.getPrices()
Modifier and Type | Method and Description |
---|---|
List<PriceDraft> |
getPrices() |
String |
getSku() |
Integer |
getVariantId() |
Boolean |
isStaged() |
static SetPrices |
of(Integer variantId,
List<PriceDraft> prices) |
static SetPrices |
ofSku(String sku,
List<PriceDraft> prices) |
static SetPrices |
ofSku(String sku,
List<PriceDraft> prices,
Boolean staged) |
static SetPrices |
ofVariantId(Integer variantId,
List<PriceDraft> prices) |
static SetPrices |
ofVariantId(Integer variantId,
List<PriceDraft> prices,
Boolean staged) |
getAction
public List<PriceDraft> getPrices()
public static SetPrices of(Integer variantId, List<PriceDraft> prices)
public static SetPrices ofVariantId(Integer variantId, List<PriceDraft> prices)
public static SetPrices ofVariantId(Integer variantId, List<PriceDraft> prices, @Nullable Boolean staged)
public static SetPrices ofSku(String sku, List<PriceDraft> prices)