@JsonIgnore static PriceDraftDsl of(final BigDecimal amount, final CurrencyUnit currencyUnit) { return of(MoneyImpl.of(amount, currencyUnit)); }
@JsonIgnore static PriceDraftDsl of(final BigDecimal amount, final CurrencyUnit currencyUnit) { return of(MoneyImpl.of(amount, currencyUnit)); }
@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); }
@Override public boolean matches(final Price value) { return PriceDraft.of(value).equals(draft); } }.describedAs("like %s", draft);
@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 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))); }); }
@Test public void selectAPriceByCurrencyInProductProjectionByKeyGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjection productProjection = client().executeBlocking(ProductProjectionByKeyGet.ofStaged(product.getKey()).withPriceSelection(PriceSelection.of(EUR))); final ProductVariant masterVariant = productProjection.getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
private void testAddPrice(final PriceDraft expectedPrice) throws Exception { withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPrice).isEqualTo(PriceDraft.of(actualPrice)); return updatedProduct; }); }
@Test public void selectAPriceByCurrencyInProductByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductByIdGet request = ProductByIdGet.of(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final Product result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductProjectionQuery() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionQuery request = ProductProjectionQuery.ofStaged() .withPredicates(m -> m.id().is(product.getId()))//to limit the test scope .withPriceSelection(PriceSelection.of(EUR));//price selection config final PagedQueryResult<ProductProjection> result = client().executeBlocking(request); assertThat(result.getCount()).isEqualTo(1); final ProductVariant masterVariant = result.getResults().get(0).getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductByKeyGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final Product loadedProduct = client().executeBlocking(ProductByKeyGet.of(product.getKey()).withPriceSelection(PriceSelection.of(EUR))); final ProductVariant masterVariant = loadedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductUpdateCommand() { ProductFixtures.withProduct(client(), product -> { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetPrices.of(1, prices)) .withPriceSelection(PriceSelection.of(EUR)); final Product updatedProduct = client().executeBlocking(cmd); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductQuery() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductQuery request = ProductQuery.of() .withPredicates(m -> m.id().is(product.getId()))//to limit the test scope .withPriceSelection(PriceSelection.of(EUR));//price selection config final PagedQueryResult<Product> result = client().executeBlocking(request); assertThat(result.getCount()).isEqualTo(1); final ProductVariant masterVariant = result.getResults().get(0).getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void prices() { checkFilter(builder -> { final ProductVariantDraft oldMaster = builder.getMasterVariant(); final ProductVariantDraft masterWithPrices = ProductVariantDraftBuilder.of(oldMaster) .prices(singletonList(PriceDraft.of(EURO_1))) .build(); return builder.masterVariant(masterWithPrices); }, m -> m.allVariants().prices()); }
@Test public void addPriceWithValidityPeriod() throws Exception { final PriceDraft expectedPrice = PriceDraft.of(MoneyImpl.of(123, EUR)) .withValidFrom(SphereTestUtils.now()) .withValidUntil(SphereTestUtils.now().withZoneSameLocal(ZoneOffset.UTC).plusHours(2)); testAddPrice(expectedPrice); }
@Test public void assignPricesToMasterVariantAccordingToAChannel() throws Exception { final String channelKey = "assignPricesToMasterVariantAccordingToAChannel"; cleanUpChannelByKey(client(), channelKey); final Product product = createInBackendByName("assignPricesToMasterVariantAccordingToAChannel"); final Channel channel = client().executeBlocking(ChannelCreateCommand.of(ChannelDraft.of(channelKey))); final PriceDraft price = PriceDraft.of(MoneyImpl.of(523, EUR)).withChannel(channel); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(MASTER_VARIANT_ID, price))); final Price readPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(readPrice.getChannel()).isEqualTo(channel.toReference()); client().executeBlocking(ProductUpdateCommand.of(updatedProduct, RemovePrice.of(readPrice))); cleanUpChannelByKey(client(), channelKey); }