public static PriceSelection createPriceSelection(final UserContext userContext) { return PriceSelection.of(userContext.currency()) .withPriceCountry(userContext.country()) .withPriceCustomerGroup(userContext.customerGroup().orElse(null)) .withPriceChannel(userContext.channel().orElse(null)); } }
@Override public PriceSelectionDsl build() { return new PriceSelectionDsl(priceCurrency, priceCountry, priceCustomerGroup, priceChannel); } }
public PriceSelectionDsl withPriceCountry(@Nullable final CountryCode priceCountry) { return newBuilder().priceCountry(priceCountry).build(); }
assertThat(searchWith(product, PriceSelection.of(EUR))).has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(USD))).isNull(); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU))) .has(price(priceWithCountry)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(DE))) .as("if the country is not present it falls back to the price without country") .has(price(simplePriceInEuro)); final String aChannelId = "4698af68-fa24-49ab-8a3e-abb113d72c0a"; assertThat(searchWith(product, PriceSelection.of(EUR).withPriceChannelId(aChannelId))) .as("if a price with the channel is not present it falls back to the price without channel") .has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceChannel(channel))) .has(price(priceWithChannel)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCustomerGroup(b2b))) .has(price(b2bPrice)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCustomerGroup(b2c))) .as("if a customer group does not have a special price the default price is used") .has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.DE) .withPriceChannel(channel).withPriceCustomerGroup(b2c))) .has(price(priceAll)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU) .withPriceChannel(channel).withPriceCustomerGroup(b2c))) .as("channel wins over country and customer group") .has(price(priceWithChannel)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU).withPriceCustomerGroup(b2c)))
@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); }); }); }); }
@Test public void priceSelectionCanBeRefined() { final PriceSelectionDsl priceSelectionWithoutCustomerGroup = FULL_PRICE_SELECTION.withPriceCustomerGroup(null); final ProductProjectionSearch priceSearchWithoutCustomer = SEARCH_WITH_FULL_PRICE_SELECTION.withPriceSelection(priceSelectionWithoutCustomerGroup); assertThat(priceSearchWithoutCustomer.httpRequestIntent().getBody().toString()) .contains("priceCurrency=EUR&priceCountry=DE&priceChannel=channel-id") .doesNotContain("priceCustomerGroup").doesNotContain("customer-group-id"); assertThat(priceSearchWithoutCustomer.getPriceSelection()).isEqualTo(priceSelectionWithoutCustomerGroup); }
public static PriceSelectionDsl of(@Nonnull final CurrencyUnit currencyUnit) { return ofCurrencyCode(currencyUnit.getCurrencyCode()); }
public PriceSelectionDsl withPriceCurrency(@Nonnull final CurrencyUnit currencyUnit) { return withPriceCurrencyCode(currencyUnit.getCurrencyCode()); }
private void sortCheck(final List<PriceDraft> prices1, final List<PriceDraft> prices2, final SortExpression<ProductProjection> sortExpression) { withProductOfPrices(prices1, product1 -> { withProductOfPrices(prices2, product2 -> { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusSort(sortExpression); assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(search); assertThat(result.getResults()).extracting(ResourceView::getId) .as("product1 with small price included").containsExactly(product1.getId(), product2.getId()); }); }); }); }
public static PriceSelectionDsl of(@Nonnull final CurrencyUnit currencyUnit) { return ofCurrencyCode(currencyUnit.getCurrencyCode()); }
public PriceSelectionDsl withPriceCurrency(@Nonnull final CurrencyUnit currencyUnit) { return withPriceCurrencyCode(currencyUnit.getCurrencyCode()); }
@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(); }); }); }); }); }
public PriceSelectionDsl withPriceCustomerGroup(@Nullable final Referenceable<CustomerGroup> priceCustomerGroup) { return newBuilder().priceCustomerGroup(priceCustomerGroup).build(); }
@Override public PriceSelectionDsl build() { return new PriceSelectionDsl(priceCurrency, priceCountry, priceCustomerGroup, priceChannel); } }
@Test public void facetSearchByScopedPriceDiscounted() { 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 -> { withProductOfPrices(asList(PriceDraft.of(EURO_40), PriceDraft.of(EURO_25).withCountry(DE)), product3 -> { final ProductDiscountDraft productDiscountDraft1 = discountDraftOfAbsoluteValue(product1, EURO_5); withProductDiscount(client(), productDiscountDraft1, productDiscount1 -> { assertEventually(s -> { final TermFacetExpression<ProductProjection> facetExpression = ProductProjectionSearchModel.of() .facet().allVariants().scopedPriceDiscounted().allTerms(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))) .withFacets(facetExpression); final PagedSearchResult<ProductProjection> results = client().executeBlocking(search); assertThat(results.getResults()).hasSize(3); final List<TermStats> termStats = results.getFacetResult(facetExpression).getTerms(); s.assertThat(termStats).containsOnly( TermStats.of(BOOL_TRUE, 1L), TermStats.of(BOOL_FALSE, 2L)); }); }); }); }); }); }
public PriceSelectionDsl withPriceChannel(@Nullable final Referenceable<Channel> priceChannel) { return newBuilder().priceChannel(priceChannel).build(); }
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() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().is(product.getId()))
public PriceSelectionDsl withPriceChannelId(@Nullable final String priceChannelId) { return newBuilder().priceChannelId(priceChannelId).build(); }
public PriceSelectionDsl withPriceCountry(@Nullable final CountryCode priceCountry) { return newBuilder().priceCountry(priceCountry).build(); }
public PriceSelectionDsl withPriceCustomerGroupId(@Nullable final String priceCustomerGroupId) { return newBuilder().priceCustomerGroupId(priceCustomerGroupId).build(); }