public interface ProductDiscountCreateCommand extends DraftBasedCreateCommandDsl<ProductDiscount,ProductDiscountDraft,ProductDiscountCreateCommand>, MetaModelReferenceExpansionDsl<ProductDiscount,ProductDiscountCreateCommand,ProductDiscountExpansionModel<ProductDiscount>>
ProductDiscount
.
final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z");
final ZonedDateTime end = start.plusYears(100);
final Product product = referenceableProduct(client());
final ProductDiscountPredicate predicate =
ProductDiscountPredicate.of("product.id = \"" + product.getId() + "\"");
final AbsoluteProductDiscountValue discountValue = AbsoluteProductDiscountValue.of(EURO_1);
final LocalizedString name = en("demo product discount");
final LocalizedString description = en("description");
final boolean active = true;
final String sortOrder = randomSortOrder();
final ProductDiscountDraft discountDraft =
ProductDiscountDraftBuilder.of()
.name(name)
.description(description)
.predicate(predicate)
.value(discountValue)
.sortOrder(sortOrder)
.isActive(active)
.validFrom(start)
.validUntil(end)
.build();
final ProductDiscount productDiscount = client().executeBlocking(ProductDiscountCreateCommand.of(discountDraft));
assertThat(productDiscount.getName()).isEqualTo(name);
assertThat(productDiscount.getDescription()).isEqualTo(description);
assertThat(productDiscount.getPredicate()).isEqualTo(predicate.toSpherePredicate());
assertThat(productDiscount.getValue()).isEqualTo(discountValue);
assertThat(productDiscount.getSortOrder()).isEqualTo(sortOrder);
assertThat(productDiscount.isActive()).isEqualTo(active);
assertThat(productDiscount.getValidFrom()).isEqualTo(start);
assertThat(productDiscount.getValidUntil()).isEqualTo(end);
final ProductByIdGet sphereRequest =
ProductByIdGet.of(product)
.plusExpansionPaths(m -> m.masterData().staged().masterVariant().prices().discounted().discount());
assertEventually(() -> {
final Product discountedProduct = client().executeBlocking(sphereRequest);
final List<Price> productPrices = discountedProduct.getMasterData().getStaged().getMasterVariant().getPrices();
assertThat(productPrices)
.overridingErrorMessage("discount object in price is expanded")
.matches(prices -> prices.stream().anyMatch(price -> price.getDiscounted() != null && price.getDiscounted().getDiscount().getObj() != null));
//Query that the messages are returned correctly
final Query<ProductPriceDiscountsSetMessage> query = MessageQuery.of()
.withPredicates(m -> m.resource().is(product))
.forMessageType(ProductPriceDiscountsSetMessage.MESSAGE_HINT);
final List<ProductPriceDiscountsSetMessage> results =
client().executeBlocking(query).getResults();
assertThat(results).isNotEmpty();
assertThat(results.get(0).getUpdatedPrices()).isNotNull();
});
// clean up test
client().executeBlocking(ProductDiscountDeleteCommand.of(productDiscount));
See the test code.
ProductDiscountDraft
,
ProductDiscount
Modifier and Type | Method and Description |
---|---|
static ProductDiscountCreateCommand |
of(ProductDiscountDraft draft)
Creates a command object to create a
ProductDiscount . |
getDraft, withDraft
canDeserialize, deserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
static ProductDiscountCreateCommand of(ProductDiscountDraft draft)
ProductDiscount
.draft
- template to create the new object