public static ChangePrice of(final Price oldPrice, final PriceDraft price) { return of(oldPrice, price, null); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price) { return of(oldPrice, price, null); }
public static ChangePrice of(final String priceId, final PriceDraft price) { return of(priceId, price, null); }
public static ChangePrice of(final String priceId, final PriceDraft price) { return of(priceId, price, null); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price, @Nullable final Boolean staged) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price, staged); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price, @Nullable final Boolean staged) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price, staged); }
@Test public void changePriceToAHigherPrecision() throws Exception { withUpdateablePricedProduct(client(), product -> { final PriceDraft newHighPrecisionPrice = PriceDraft.of(HighPrecisionMoneyImpl.of(new BigDecimal("15.3669996"),EUR,7)); final List<Price> prices = product.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newHighPrecisionPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, ChangePrice.of(prices.get(0), newHighPrecisionPrice))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newHighPrecisionPrice); return updatedProduct; }); }
@Test public void changePrice() throws Exception { withUpdateablePricedProduct(client(), product -> { final PriceDraft newPrice = PriceDraft.of(MoneyImpl.of(234, EUR)); final List<Price> prices = product.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, ChangePrice.of(prices.get(0), newPrice))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newPrice); return updatedProduct; }); }
@Test public void changePriceAddTiers() throws Exception { withUpdateablePricedProduct(client(), product -> { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_5).build()); final PriceDraft newPrice = PriceDraftBuilder.of(MoneyImpl.of(234, EUR)) .tiers(tiers) .build(); final List<Price> prices = product.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, ChangePrice.of(prices.get(0), newPrice))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newPrice); return updatedProduct; }); }
public void changePriceWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { final ProductUpdateCommand command = ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, PriceDraft.of(MoneyImpl.of(123, EUR)), false)); final Product productWithPrice = client().executeBlocking(command); assertThat(productWithPrice.getMasterData().hasStagedChanges()).isFalse(); final PriceDraft newPrice = PriceDraft.of(MoneyImpl.of(234, EUR)); final List<Price> prices = productWithPrice.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(productWithPrice, ChangePrice.of(prices.get(0), newPrice, staged))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newPrice); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void recalculate() throws Exception { withEmptyCartAndProduct(client(), (emptyCart, product) -> { final AddLineItem action = AddLineItem.of(product.getId(), MASTER_VARIANT_ID, 1L); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(emptyCart, action)); final Price oldPrice = cartWithLineItem.getLineItems().get(0).getPrice(); final PriceDraft priceDraft = PriceDraft.of(oldPrice).withValue(oldPrice.getValue().multiply(2)); final Product productWithChangedPrice = client().executeBlocking(ProductUpdateCommand.of(product, asList(ChangePrice.of(oldPrice, priceDraft), Publish.of()))); final List<Price> prices = productWithChangedPrice.getMasterData().getCurrent().getMasterVariant().getPrices(); assertThat(prices.stream().map(price -> PriceDraft.of(price)).collect(Collectors.toList())) .as("we updated the price of the product") .isEqualTo(asList(priceDraft)); final LineItem lineItemOfTheChangedProduct = client().executeBlocking(CartByIdGet.of(cartWithLineItem)).getLineItems().get(0); assertThat(lineItemOfTheChangedProduct.getPrice()) .as("the new product price is not automatically propagated to the line item in the cart") .isEqualTo(oldPrice).isNotEqualTo(priceDraft); final Cart recalculatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithLineItem, Recalculate.of())); assertThat(PriceDraft.of(recalculatedCart.getLineItems().get(0).getPrice())) .as("recalculate updated the price of the line item in the cart") .isEqualTo(priceDraft); assertThat(recalculatedCart.getTotalPrice()) .as("recalculate also updated the total price of the cart") .isEqualTo(priceDraft.getValue()).isNotEqualTo(cartWithLineItem.getTotalPrice()); }); }