public static PriceDraftBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(Optional.ofNullable(template.getChannel()).map(Referenceable::toResourceIdentifier).orElse(null)) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(copyCustom(template)); } }
public static PriceDraftBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(Optional.ofNullable(template.getChannel()).map(Referenceable::toResourceIdentifier).orElse(null)) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(copyCustom(template)); } }
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(); }
public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()); }
public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()); }
/** * 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 canExpandChannelOfPrices() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().channel().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
public static PriceDraftDsl of(final Price template) { return PriceDraftBuilder.of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .custom(customFieldsDraftOrNull(template)) .build(); }
@Test public void expandChannelInPrice() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().channel()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .id(template.getId()); }
@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); }