public static PriceDraftDsl of(final Price template) { final ResourceIdentifier<Channel> channelResourceIdentifier = Optional.ofNullable(template.getChannel()).map(Referenceable::toResourceIdentifier).orElse(null); return PriceDraftBuilder.of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(channelResourceIdentifier) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(customFieldsDraftOrNull(template)) .tiers(template.getTiers()) .build(); }
public static PriceDraftDsl of(final Price template) { final ResourceIdentifier<Channel> channelResourceIdentifier = Optional.ofNullable(template.getChannel()).map(Referenceable::toResourceIdentifier).orElse(null); return PriceDraftBuilder.of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(channelResourceIdentifier) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(customFieldsDraftOrNull(template)) .tiers(template.getTiers()) .build(); }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static PriceBuilder of(final Price template) { return new PriceBuilder(template.getChannel(), template.getCountry(), template.getCustom(), template.getCustomerGroup(), template.getDiscounted(), template.getId(), template.getTiers(), template.getValidFrom(), template.getValidUntil(), template.getValue()); } }
@Test public void createProductWithTiers() { withEmptyProductType(client(), randomKey(), productType -> withUpdateableType(client(), type -> { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_5).build()); final PriceDraft priceWithTiers = PriceDraftBuilder.of(EURO_1) .tiers(tiers) .build(); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .price(priceWithTiers) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Price loadedPrice = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(loadedPrice.getValue()).isEqualTo(EURO_1); assertThat(loadedPrice.getTiers()).containsExactlyElementsOf(tiers); client().executeBlocking(ProductDeleteCommand.of(product)); return type; }) ); }