public interface DiscountCodeCreateCommand extends DraftBasedCreateCommandDsl<DiscountCode,DiscountCodeDraft,DiscountCodeCreateCommand>, MetaModelReferenceExpansionDsl<DiscountCode,DiscountCodeCreateCommand,DiscountCodeExpansionModel<DiscountCode>>
DiscountCode
.
withPersistentCartDiscount(client(), cartDiscount -> { final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z"); final ZonedDateTime end = start.plusYears(100); final String code = randomKey(); final DiscountCodeDraft draft = DiscountCodeDraftBuilder.of(code, cartDiscount) .name(en(DiscountCodeCreateCommandIntegrationTest.class.getName())) .description(en("sample discount code descr.")) .cartPredicate(CartPredicate.of("1 = 1")) .isActive(false) .maxApplications(5L) .validFrom(start) .validUntil(end) .maxApplicationsPerCustomer(1L) .groups(asList("DiscountGroup1")) .build(); final DiscountCodeCreateCommand createCommand = DiscountCodeCreateCommand.of(draft) .plusExpansionPaths(m -> m.cartDiscounts()); final DiscountCode discountCode = client().executeBlocking(createCommand); assertThat(discountCode.getCode()).isEqualTo(code); assertThat(discountCode.getName()).isEqualTo(en(DiscountCodeCreateCommandIntegrationTest.class.getName())); assertThat(discountCode.getDescription()).isEqualTo(en("sample discount code descr.")); assertThat(discountCode.getValidFrom()).isEqualTo(start); assertThat(discountCode.getValidUntil()).isEqualTo(end); final Reference<CartDiscount> cartDiscountReference = discountCode.getCartDiscounts().get(0); assertThat(cartDiscountReference) .isEqualTo(cartDiscount.toReference()) .is(expanded()); assertThat(discountCode.getCartPredicate()).contains("1 = 1"); assertThat(discountCode.isActive()).isEqualTo(false); assertThat(discountCode.getMaxApplications()).isEqualTo(5L); assertThat(discountCode.getMaxApplicationsPerCustomer()).isEqualTo(1L); assertThat(discountCode.getGroups()).containsExactly("DiscountGroup1"); //clean up client().executeBlocking(DiscountCodeDeleteCommand.of(discountCode)); });
See the test code.
DiscountCodeDraft
,
DiscountCode
Modifier and Type | Method and Description |
---|---|
static DiscountCodeCreateCommand |
of(DiscountCodeDraft draft)
Creates a command object to create a
DiscountCode . |
getDraft, withDraft
canDeserialize, deserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
static DiscountCodeCreateCommand of(DiscountCodeDraft draft)
DiscountCode
.draft
- template to create the new object