public static PriceDraftBuilder of(final PriceDraft template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(template.getCustom()); }
@JsonIgnore static PriceDraftDsl of(final BigDecimal amount, final CurrencyUnit currencyUnit) { return of(MoneyImpl.of(amount, currencyUnit)); }
@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()); }); }
@Test public void withCountryCode() { final PriceDraft draft = PriceDraftDsl.of(MoneyImpl.ofCents(123, "EUR")).withCountryCode("DE"); assertThat(draft.getCountry()).isEqualTo(CountryCode.DE); }
@Test public void withCustomerGroupId() { final String customerGroupId = "foo"; final PriceDraft draft = PriceDraftDsl.of(MoneyImpl.ofCents(123, "EUR")).withCustomerGroupId(customerGroupId); assertThat(draft.getCustomerGroup().getId()).isEqualTo(customerGroupId); } }
public static PriceDraftBuilder of(final PriceDraft template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(template.getCustom()); }
@JsonIgnore static PriceDraftDsl of(final BigDecimal amount, final CurrencyUnit currencyUnit) { return of(MoneyImpl.of(amount, currencyUnit)); }
public static PriceDraftBuilder of(final PriceDraft template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(template.getCustom()); }
@JsonIgnore static PriceDraftDsl of(final BigDecimal amount, final CurrencyUnit currencyUnit) { return of(MoneyImpl.of(amount, currencyUnit)); }
/** * @deprecated use LineItemImportDraftBuilder{@link #of(ProductVariantImportDraft, long, PriceDraft, LocalizedString)} instead. */ @Deprecated public static LineItemImportDraftBuilder of(final ProductVariantImportDraft variant, final long quantity, final Price price, final LocalizedString name) { return new LineItemImportDraftBuilder(variant, quantity, PriceDraft.of(price), variant.getProductId(), name); }
/** * @deprecated use LineItemImportDraftBuilder{@link #of(ProductVariantImportDraft, long, PriceDraft, LocalizedString)} instead. */ @Deprecated public static LineItemImportDraftBuilder of(final ProductVariantImportDraft variant, final long quantity, final Price price, final LocalizedString name) { return new LineItemImportDraftBuilder(variant, quantity, PriceDraft.of(price), variant.getProductId(), name); }
public void assertEqualPrice(final Price price,final PriceDraft priceDraft){ assertThat(priceDraft).isEqualTo(PriceDraft.of(price)); }
@Override public boolean matches(final Price value) { return PriceDraft.of(value).equals(draft); } }.describedAs("like %s", draft);
public static void withUpdateablePricedProduct(final BlockingSphereClient client, final Function<Product, Product> f) { withUpdateablePricedProduct(client, PriceDraft.of(MoneyImpl.of(123, EUR)), f); }
@Test public void addPriceYen() throws Exception { final PriceDraft expectedPrice = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); testAddPrice(expectedPrice); }
@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 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 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; }); }
public void addPriceByVariantIdWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, priceDraft, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void selectAPriceByCurrencyInProductProjectionByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionByIdGet request = ProductProjectionByIdGet.ofStaged(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final ProductProjection result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }