protected Optional<PriceLike> resolvePrice(final ProductVariant variant) { PriceLike price = firstNonNull(variant.getPrice(), variant.getScopedPrice()); return Optional.ofNullable(price); }
@Test public void filterByValueCentAmountAndCountry() { withProductOfPrices(asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)), product1 -> { withProductOfPrices(asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)), product2 -> { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusQueryFilters(m -> m.allVariants().scopedPrice().value() .centAmount().isLessThanOrEqualTo(3000L)); assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(search); assertThat(result.getResults()).extracting(ResourceView::getId) .as("product1 with small price included").contains(product1.getId()) .as("product2 is expensive in the scope, not included").doesNotContain(product2.getId()); final ProductVariant masterVariant = result.getResults().get(0).getMasterVariant(); final Price price = masterVariant.getPrice(); assertThat(price).as("price").isNotNull(); assertThat(price.getValue()).isEqualTo(EURO_30); assertThat(masterVariant.getScopedPrice()).isNotNull(); assertThat(masterVariant.getScopedPrice().getValue()).as("scopedPrice").isEqualTo(EURO_30); }); }); }); }
resultForCurrentValue.getResults().get(0).findFirstMatchingVariant().orElse(null); s.assertThat(matchingVariant).isNotNull(); s.assertThat(matchingVariant.getScopedPrice().getValue()).as("value").isEqualTo(EURO_30); s.assertThat(matchingVariant.getScopedPrice().getDiscounted()).isNotNull(); final MonetaryAmount discountedValue = matchingVariant.getScopedPrice().getDiscounted().getValue(); s.assertThat(discountedValue).as("discountedValue from the selected scope").isEqualTo(EURO_25) .as("does not use the fallback price").isNotEqualTo(EURO_20) .as("or the discounted fallback price").isNotEqualTo(EURO_15); s.assertThat(matchingVariant.getScopedPrice().getDiscounted().getDiscount()) .isEqualTo(productDiscount.toReference()); s.assertThat(matchingVariant.isScopedPriceDiscounted()).isTrue(); s.assertThat(matchingVariant.getScopedPrice()).isNotNull(); s.assertThat(matchingVariant.getScopedPrice().getCurrentValue()) .as("currentValue").isEqualTo(discountedValue); final ProductVariant discountedVariant = results.get(0).findFirstMatchingVariant().orElse(null); assertThat(discountedVariant).isNotNull(); s.assertThat(discountedVariant.getScopedPrice()).isEqualTo(matchingVariant.getScopedPrice()); }); });