public final class ProductVariantFilterSearchModel extends SearchModelImpl<ProductProjection>
Modifier and Type | Method and Description |
---|---|
ProductAttributeFilterSearchModel |
attribute() |
ProductVariantAvailabilityFilterSearchModel<ProductProjection> |
availability() |
TermFilterExistsAndMissingSearchModel<ProductProjection,String> |
key() |
MoneyFilterSearchModel<ProductProjection> |
price() |
ExistsAndMissingFilterSearchModelSupport<ProductProjection> |
prices() |
ScopedPriceFilterSearchModel<ProductProjection> |
scopedPrice()
Provides filters for scoped prices.
|
TermFilterExistsAndMissingSearchModel<ProductProjection,Boolean> |
scopedPriceDiscounted()
Creates filters for the scopedPriceDiscounted property of a product variant.
|
TermFilterExistsAndMissingSearchModel<ProductProjection,String> |
sku()
Creates filters for the sku property of a product variant.
|
booleanSearchModel, dateSearchModel, datetimeSearchModel, enumFacetedSearchSearchModel, enumFacetSearchModel, enumFilterSearchModel, existsAndMissingFilterSearchModelSupport, existsFilters, getParent, getPathSegment, localizedEnumFacetedSearchSearchModel, localizedEnumFacetSearchModel, localizedEnumFilterSearchModel, localizedStringFacetedSearchSearchModel, localizedStringFacetSearchModel, localizedStringFilterSearchModel, missingFilters, moneyFacetedSearchSearchModel, moneyFacetSearchModel, moneyFilterSearchModel, numberSearchModel, referenceFacetedSearchSearchModel, referenceFacetSearchModel, referenceFilterSearchModel, searchModel, stringSearchModel, timeSearchModel
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
attributePath, buildPath, hasPath
public ProductAttributeFilterSearchModel attribute()
public ProductVariantAvailabilityFilterSearchModel<ProductProjection> availability()
public MoneyFilterSearchModel<ProductProjection> price()
public ScopedPriceFilterSearchModel<ProductProjection> scopedPrice()
Simple example:
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); }); }); });
See the test code.
Example with a discount:
withProductOfPrices(asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)), product -> { final ProductDiscountDraft productDiscountDraft = discountDraftOfAbsoluteValue(product, EURO_5); withProductDiscount(client(), productDiscountDraft, productDiscount -> { assertEventually(s -> { final ProductProjectionSearch searchForCurrentValue = ProductProjectionSearch.ofStaged() .withMarkingMatchingVariants(true) .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().scopedPrice().currentValue() .centAmount().isLessThanOrEqualTo(2500L)) .plusQueryFilters(m -> m.allVariants().scopedPriceDiscounted().is(true)); final PagedSearchResult<ProductProjection> resultForCurrentValue = client().executeBlocking(searchForCurrentValue); assertThat(resultForCurrentValue.getResults()).hasSize(1) .as("currentValue search finds discounted price") .extracting(ResourceView::getId).contains(product.getId()); final ProductVariant matchingVariant = 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); //it is also possible to filter for discounted values final ProductProjectionSearch searchForDiscountedValue = ProductProjectionSearch.ofStaged() .withMarkingMatchingVariants(true) .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().is(product.getId())) //filter by discounted value .plusQueryFilters(m -> m.allVariants().scopedPrice().discounted().value() .centAmount().isLessThanOrEqualTo(2500L)) //also possible to filter for a specific discount .plusQueryFilters(m -> m.allVariants().scopedPrice() .discounted().discount().id().is(productDiscount.getId())); final PagedSearchResult<ProductProjection> discountedSearchResult = client().executeBlocking(searchForDiscountedValue); final List<ProductProjection> results = discountedSearchResult.getResults(); assertThat(results).hasSize(1); final ProductVariant discountedVariant = results.get(0).findFirstMatchingVariant().orElse(null); assertThat(discountedVariant).isNotNull(); s.assertThat(discountedVariant.getScopedPrice()).isEqualTo(matchingVariant.getScopedPrice()); }); }); });
See the test code.
public TermFilterExistsAndMissingSearchModel<ProductProjection,Boolean> scopedPriceDiscounted()
withProductOfPrices(asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)), product -> { final ProductDiscountDraft productDiscountDraft = discountDraftOfAbsoluteValue(product, EURO_5); withProductDiscount(client(), productDiscountDraft, productDiscount -> { assertEventually(s -> { final ProductProjectionSearch searchForCurrentValue = ProductProjectionSearch.ofStaged() .withMarkingMatchingVariants(true) .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().scopedPrice().currentValue() .centAmount().isLessThanOrEqualTo(2500L)) .plusQueryFilters(m -> m.allVariants().scopedPriceDiscounted().is(true)); final PagedSearchResult<ProductProjection> resultForCurrentValue = client().executeBlocking(searchForCurrentValue); assertThat(resultForCurrentValue.getResults()).hasSize(1) .as("currentValue search finds discounted price") .extracting(ResourceView::getId).contains(product.getId()); final ProductVariant matchingVariant = 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); //it is also possible to filter for discounted values final ProductProjectionSearch searchForDiscountedValue = ProductProjectionSearch.ofStaged() .withMarkingMatchingVariants(true) .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().is(product.getId())) //filter by discounted value .plusQueryFilters(m -> m.allVariants().scopedPrice().discounted().value() .centAmount().isLessThanOrEqualTo(2500L)) //also possible to filter for a specific discount .plusQueryFilters(m -> m.allVariants().scopedPrice() .discounted().discount().id().is(productDiscount.getId())); final PagedSearchResult<ProductProjection> discountedSearchResult = client().executeBlocking(searchForDiscountedValue); final List<ProductProjection> results = discountedSearchResult.getResults(); assertThat(results).hasSize(1); final ProductVariant discountedVariant = results.get(0).findFirstMatchingVariant().orElse(null); assertThat(discountedVariant).isNotNull(); s.assertThat(discountedVariant.getScopedPrice()).isEqualTo(matchingVariant.getScopedPrice()); }); }); });
See the test code.
public ExistsAndMissingFilterSearchModelSupport<ProductProjection> prices()
public TermFilterExistsAndMissingSearchModel<ProductProjection,String> sku()
final List<String> skus = Stream.of(product1, product2) .map(product -> product.getMasterData().getStaged().getMasterVariant().getSku()) .collect(toList()); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.allVariants().sku().isIn(skus)); assertEventually(Duration.ofSeconds(45), Duration.ofMillis(200), () -> { assertThat(client().executeBlocking(search).getResults()) .extracting(m -> m.getMasterVariant().getSku()) .containsOnly(skus.get(0), skus.get(1)); });
See the test code.
public TermFilterExistsAndMissingSearchModel<ProductProjection,String> key()