public final class ExternalProductDiscountValue extends Base implements ProductDiscountValue
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 |
---|---|
static ExternalProductDiscountValue |
of() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
ofAbsolute, ofAbsolute, ofExternal, ofRelative
public static ExternalProductDiscountValue of()