public interface ProductVariantAvailabilityFilterSearchModel<T>
Modifier and Type | Method and Description |
---|---|
RangeTermFilterSearchModel<T,BigDecimal> |
availableQuantity()
Helper to build search requests filtering for ranges of product availability.
|
ChannelsProductVariantAvailabilityFilterSearchModel<T> |
channels() |
TermFilterSearchModel<T,Boolean> |
isOnStock()
Helper to build search requests including products which are available.
|
TermFilterSearchModel<T,String> |
onStockInChannels()
Returns a filter search model for product variant availabilities by channels with
ProductVariantAvailability.isOnStock() equal to true . |
TermFilterSearchModel<T,Boolean> isOnStock()
Example without channels:
withProductOfStock(client(), 2, product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability().isOnStock().is(true)); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); }); });
See the test code.
Example with a channel:
withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 2, channel, product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .channels().channelId(channel.getId()).isOnStock().is(true)); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); }); }); });
See the test code.
TermFilterSearchModel<T,String> onStockInChannels()
ProductVariantAvailability.isOnStock()
equal to true
.
final String nonExistingChannel = "nonExistingChannelId"; withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 2, channel, product -> { final ProductProjectionSearch isOnStockInAnyChannelRequest = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .onStockInChannels().containsAny(Arrays.asList(nonExistingChannel, channel.getId()))); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(isOnStockInAnyChannelRequest); assertThat(res.getResults()).hasSize(1); }); final ProductProjectionSearch isOnStockInAllChannelsRequest = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .onStockInChannels().containsAll(Arrays.asList(nonExistingChannel, channel.getId()))); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(isOnStockInAllChannelsRequest); assertThat(res.getResults()).isEmpty(); }); }); });
See the test code.
RangeTermFilterSearchModel<T,BigDecimal> availableQuantity()
Example without channels:
withProductOfStock(client(), 10, productWith10Items -> { withProductOfStock(client(), 5, productWith5Items -> { final RangeFacetExpression<ProductProjection> productProjectionRangeFacetExpression = ProductProjectionSearchModel.of() .facet().allVariants().availability().availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(productProjectionRangeFacetExpression); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(productProjectionRangeFacetExpression); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); });
See the test code.
Example with a channel:
withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 10, channel, productWith10Items -> { withProductOfStockAndChannel(client(), 5, channel, productWith5Items -> { final RangeFacetExpression<ProductProjection> facet = ProductProjectionSearchModel.of() .facet().allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(facet); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(facet); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); }); });
See the test code.
ChannelsProductVariantAvailabilityFilterSearchModel<T> channels()