public ProductVariantSortSearchModel allVariants() { return new ProductVariantSortSearchModel(this, "variants"); }
public MultiValueSortSearchModel<ProductProjection> price() { return searchModel(/*sic! price is at top level*/null, "price").sorted(); } }
@Test public void onNumberAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofNumber(ATTR_NAME_NUMBER).desc(), ids -> assertThat(ids).containsExactly(product2.getId(), product1.getId())); }
@Test public void canAccessPriceAmount() throws Exception { assertThat(FACET_MODEL.allVariants().price().centAmount().allTerms().expression()).isEqualTo("variants.price.centAmount"); assertThat(FILTER_MODEL.allVariants().price().centAmount().is(1000L)).extracting(expression()).containsExactly("variants.price.centAmount:1000"); assertThat(SORT_MODEL.allVariants().price().descWithMinValue().expression()).isEqualTo("price desc.min"); }
@Test public void channelsRestockableSortDsl() { final StringHttpRequestBody body = (StringHttpRequestBody) ProductProjectionSearch.ofStaged(). plusSort(m -> m.allVariants().availability().channels().channelId("channel-id-500").restockableInDays().asc()).httpRequestIntent().getBody(); assertThat(body.getString()).contains("sort=variants.availability.channels.channel-id-500.restockableInDays+asc"); }
@Test public void canAccessScopedPriceDiscounted() throws Exception { assertThat(FACET_MODEL.allVariants().scopedPriceDiscounted().allTerms().expression()).isEqualTo("variants.scopedPriceDiscounted"); assertThat(FILTER_MODEL.allVariants().scopedPriceDiscounted().is(true)).extracting(expression()).containsExactly("variants.scopedPriceDiscounted:true"); assertThat(SORT_MODEL.allVariants().scopedPriceDiscounted().asc().expression()).isEqualTo("variants.scopedPriceDiscounted asc"); }
@Test public void onSku() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().sku().asc(), ids -> assertThat(ids).containsExactly(product1.getId(), product2.getId())); } @Test
@Test public void sortByCurrentScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().currentValue().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
@Test public void onBooleanSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofBooleanSet(ATTR_NAME_BOOLEAN_SET).asc(), ids -> assertThat(ids).containsExactly(product1.getId(), product2.getId())); }
/** * Gets the products belonging to the given categories, up to {@code numProducts}, most expensive products first. * @param categoryIds the category IDs to get products from * @param numProducts the number of products the returned set should contain * @return the products related to these categories */ private CompletionStage<Set<ProductProjection>> productsFromCategoryIds(final Iterable<String> categoryIds, final int numProducts) { final ProductProjectionSearch request = ProductProjectionSearch.ofCurrent() .withLimit(numProducts) .withQueryFilters(product -> product.categories().id().containsAny(categoryIds)) .withSort(product -> product.allVariants().price().desc()) .withPriceSelection(PriceUtils.createPriceSelection(userContext)); return sphereClient.execute(request) .whenCompleteAsync((result, t) -> logProductRequest(LOGGER, request, result), HttpExecution.defaultContext()) .thenApply(SunriseProductRecommendation::resultToProductSet); }
@Test public void sortByRestockableInDays() { withProductOfRestockableInDaysAndChannel(client(), 4, null, product4 -> { withProductOfRestockableInDaysAndChannel(client(), 9, null, product9 -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(product4.getId(), product9.getId()))) .plusSort(m -> m.allVariants().availability().restockableInDays().asc()); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(2); assertThat(res.getResults().get(0).getId()) .isEqualTo(product4.getId()); }); }); }); }
@Test public void sortByScopedPriceDiscounted() { 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 ProductDiscountDraft productDiscountDraft1 = discountDraftOfAbsoluteValue(product1, EURO_5); withProductDiscount(client(), productDiscountDraft1, productDiscount1 -> { assertEventually(s -> { //Products ordered by scopedPriceDiscounted (ascending) final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusSort(m -> m.allVariants().scopedPriceDiscounted().asc()); final PagedSearchResult<ProductProjection> results = client().executeBlocking(search); assertThat(results.getResults()).hasSize(2); s.assertThat(results.getResults()).extracting(ResourceView::getId).containsExactly(product2.getId(), product1.getId()); //Products ordered by scopedPriceDiscounted (descending) final ProductProjectionSearch searchDescending = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusSort(m -> m.allVariants().scopedPriceDiscounted().desc()); final PagedSearchResult<ProductProjection> resultsDescending = client().executeBlocking(searchDescending); assertThat(resultsDescending.getResults()).hasSize(2); s.assertThat(resultsDescending.getResults()).extracting(ResourceView::getId).containsExactly(product1.getId(), product2.getId()); assertThat(resultsDescending.getResults().get(0).getMasterVariant().getPrice().getDiscounted()).isNotNull(); }); }); }); }); }
@Test public void canAccessSku() throws Exception { final String sku = "sku-test"; assertThat(FILTER_MODEL.allVariants().sku().is(sku)).extracting(expression()).containsExactly("variants.sku:\"" + sku +"\""); assertThat(SORT_MODEL.allVariants().sku().asc().expression()).isEqualTo("variants.sku asc"); }
@Test public void sortByValueScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().value().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
@Test public void onDateAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofDate(ATTR_NAME_DATE).desc(), ids -> assertThat(ids).containsExactly(product2.getId(), product1.getId())); }
public MultiValueSortSearchModel<ProductProjection> sku() { return searchModel("sku").sorted(); } }
public ProductVariantSortSearchModel allVariants() { return new ProductVariantSortSearchModel(this, "variants"); }
@Test public void sortByAvailableQuantity() { withProductOfStock(client(), 10, productWith10Items -> { withProductOfStock(client(), 5, productWith5Items -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith5Items.getId(), productWith10Items.getId()))) .plusSort(m -> m.allVariants().availability().availableQuantity().asc()); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(2); assertThat(res.getResults().get(0).getId()) .isEqualTo(productWith5Items.getId()); }); }); }); }
@Test public void onDateTimeAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofDateTime(ATTR_NAME_DATE_TIME).desc(), ids -> assertThat(ids).containsExactly(product2.getId(), product1.getId())); }
public MultiValueSortSearchModel<ProductProjection> sku() { return searchModel("sku").sorted(); } }