@Test public void changeOrderHint() throws Exception { withCategory(client(), category -> { final String newOrderHint = randomSortOrder(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, ChangeOrderHint.of(newOrderHint)); final Category updatedCategory = client().executeBlocking(command); assertThat(updatedCategory.getOrderHint()).isEqualTo(newOrderHint); }); }
@Test public void changeSortOrder() throws Exception { withPersistentCartDiscount(client(), cartDiscount -> { final String newSortOrder = randomSortOrder(); assertThat(cartDiscount.getSortOrder()).isNotEqualTo(newSortOrder); final CartDiscount updatedDiscount = client().executeBlocking(CartDiscountUpdateCommand.of(cartDiscount, ChangeSortOrder.of(newSortOrder))); assertThat(updatedDiscount.getSortOrder()).isEqualTo(newSortOrder); }); }
@Test public void changeSortOrder() throws Exception { withUpdateableProductDiscount(client(), discount -> { final String newSortOrder = randomSortOrder(); final ProductDiscount updatedDiscount = client().executeBlocking(ProductDiscountUpdateCommand.of(discount, ChangeSortOrder.of(newSortOrder))); assertThat(updatedDiscount.getSortOrder()).isEqualTo(newSortOrder); return updatedDiscount; }); } }
private ProductDiscountDraft discountDraftOfAbsoluteValue(final Product product, final MonetaryAmount amount) { final AbsoluteProductDiscountValue value = ProductDiscountValue.ofAbsolute(amount); final ProductDiscountPredicate predicate = ProductDiscountPredicate.of("product.id = \"" + product.getId() + "\""); return ProductDiscountDraft.of(randomSlug(), randomSlug(), predicate, value, randomSortOrder(), true); }
public void setDiscountedPriceWithStaged(final Boolean staged) { final ProductDiscountPredicate predicate = ProductDiscountPredicate.of("1 = 1");//can be used for all products final ProductDiscountDraft productDiscountDraft = ProductDiscountDraft.of(randomSlug(), randomSlug(), predicate, ExternalProductDiscountValue.of(), randomSortOrder(), true); //don't forget that one product discount can be used for multiple products withProductDiscount(client(), productDiscountDraft, externalProductDiscount -> { withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_40)), product -> { final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final Price originalPrice = publishedProduct.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()), staged); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, action)); final Price stagedPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(stagedPrice.getValue()).isEqualTo(EURO_40); assertThat(stagedPrice.getDiscounted().getValue()).isEqualTo(EURO_5); assertThat(stagedPrice.getDiscounted().getDiscount()).isEqualTo(externalProductDiscount.toReference()); final Price currentPrice = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices().get(0); if (staged) { assertThat(stagedPrice).isNotEqualTo(currentPrice); } else { assertThat(stagedPrice).isEqualTo(currentPrice); } }); }); }
private static CartDiscountDraftBuilder newCartDiscountDraftBuilder(final String predicate) { final ZonedDateTime validFrom = ZonedDateTime.now().minusHours(1); final ZonedDateTime validUntil = validFrom.plusSeconds(8000); final LocalizedString name = en("discount name"); final LocalizedString description = en("discount descriptions"); final AbsoluteCartDiscountValue value = CartDiscountValue.ofAbsolute(MoneyImpl.of(10, EUR)); final LineItemsTarget target = LineItemsTarget.of("1 = 1"); final String sortOrder = randomSortOrder(); final boolean requiresDiscountCode = false; return CartDiscountDraftBuilder.of(name, CartPredicate.of(predicate), value, target, sortOrder, requiresDiscountCode) .validFrom(validFrom) .validUntil(validUntil) .description(description); }
final ProductDiscountPredicate predicate = ProductDiscountPredicate.of("1 = 1");//can be used for all products final ProductDiscountDraft productDiscountDraft = ProductDiscountDraft.of(randomSlug(), randomSlug(), predicate, ExternalProductDiscountValue.of(), randomSortOrder(), true);
final MonetaryAmount discountAmount = EURO_1; final AbsoluteCartDiscountValue value = CartDiscountValue.ofAbsolute(discountAmount); final CartDiscountDraft discountDraft = CartDiscountDraftBuilder.of(name, cartPredicate, value, LineItemsTarget.ofAll(), randomSortOrder(), false) .build(); final CartDiscount cartDiscount = client().executeBlocking(CartDiscountCreateCommand.of(discountDraft));
final LocalizedString description = en("description"); final boolean active = true; final String sortOrder = randomSortOrder(); final ProductDiscountDraft discountDraft = ProductDiscountDraftBuilder.of()
public static void withUpdateableProductDiscount(final BlockingSphereClient client, final BiFunction<ProductDiscount, Product, ProductDiscount> function) { withUpdateableProduct(client, builder -> builder.masterVariant(ProductVariantDraftBuilder.of().price(PRICE).build()), product -> { 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 = ProductDiscountDraft.of(name, description, predicate, discountValue, sortOrder, active); final ProductDiscount productDiscount = client.executeBlocking(ProductDiscountCreateCommand.of(discountDraft)); final ProductDiscount updatedDiscount = function.apply(productDiscount, product); client.executeBlocking(ProductDiscountDeleteCommand.of(updatedDiscount)); return client.executeBlocking(ProductByIdGet.of(product)); }); }