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)); } }
@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); }
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))) .as("country wins over customer group") .has(price(priceWithCountry));