public final class SetDiscountedPrice extends UpdateActionImpl<T>
See also ProductUpdateCommand.
final ProductDiscountPredicate predicate = ProductDiscountPredicate.of("1 = 1");//can be used for all products
final ProductDiscountDraft productDiscountDraft = ProductDiscountDraft.of(randomSlug(), randomKey(), randomSlug(),
predicate, ExternalProductDiscountValue.of(), randomSortOrder(), true);
//don't forget that one product discount can be used for multiple products
withProductDiscount(client(), productDiscountDraft, externalProductDiscount -> {
withUpdateablePricedProduct(client(), product -> {
final Price originalPrice = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0);
assertThat(originalPrice.getDiscounted()).isNull();
final String priceId = originalPrice.getId();
final SetDiscountedPrice action =
SetDiscountedPrice.of(priceId, DiscountedPrice.of(EURO_5, externalProductDiscount.toReference()));
final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, action));
final Price updatedPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0);
assertThat(updatedPrice.getValue()).isEqualTo(originalPrice.getValue());
assertThat(updatedPrice.getDiscounted().getValue()).isEqualTo(EURO_5);
assertThat(updatedPrice.getDiscounted().getDiscount()).isEqualTo(externalProductDiscount.toReference());
assertEventually(() -> {
final Query<ProductPriceExternalDiscountSetMessage> query = MessageQuery.of()
.withPredicates(m -> m.resource().is(product))
.forMessageType(ProductPriceExternalDiscountSetMessage.MESSAGE_HINT);
final List<ProductPriceExternalDiscountSetMessage> results =
client().executeBlocking(query).getResults();
assertThat(results).hasSize(1);
final ProductPriceExternalDiscountSetMessage message = results.get(0);
assertThat(message.getPriceId()).isEqualTo(priceId);
});
return updatedProduct;
});
});
See the test code.
Modifier and Type | Method and Description |
---|---|
DiscountedPrice |
getDiscounted() |
String |
getPriceId() |
Boolean |
isStaged() |
static SetDiscountedPrice |
of(String priceId,
DiscountedPrice discounted) |
static SetDiscountedPrice |
of(String priceId,
DiscountedPrice discounted,
Boolean staged) |
getAction
public String getPriceId()
@Nullable public DiscountedPrice getDiscounted()
public static SetDiscountedPrice of(String priceId, @Nullable DiscountedPrice discounted)
public static SetDiscountedPrice of(String priceId, @Nullable DiscountedPrice discounted, @Nullable Boolean staged)