private static CustomFieldsDraft customFieldsDraftOrNull(final Price template) { return Optional.ofNullable(template.getCustom()) .map(CustomFieldsDraft::ofCustomFields) .orElse(null); } }
/** * 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()); } }
private static CustomFieldsDraft customFieldsDraftOrNull(final Price template) { return Optional.ofNullable(template.getCustom()) .map(CustomFieldsDraft::ofCustomFields) .orElse(null); } }
private static CustomFieldsDraft customFieldsDraftOrNull(final Price template) { return Optional.ofNullable(template.getCustom()) .map(CustomFieldsDraft::ofCustomFields) .orElse(null); } }
private static CustomFieldsDraft copyCustom(Price template) { return Optional.ofNullable(template.getCustom()) .map(customFields -> CustomFieldsDraftBuilder.of(customFields).build()) .orElse(null); }
private static CustomFieldsDraft copyCustom(Price template) { return Optional.ofNullable(template.getCustom()) .map(customFields -> CustomFieldsDraftBuilder.of(customFields).build()) .orElse(null); }
public void setProductPriceCustomTypeAndsetProductPriceCustomFieldWithStaged(final Boolean staged) { withUpdateableType(client(), type -> { 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 String priceId = getFirstPrice(productWithPrice).getId(); final UpdateAction<Product> updateAction = SetProductPriceCustomType. ofTypeIdAndObjects(type.getId(), STRING_FIELD_NAME, "a value", priceId, staged); final ProductUpdateCommand productUpdateCommand = ProductUpdateCommand.of(productWithPrice, updateAction); final Product updatedProduct = client().executeBlocking(productUpdateCommand); final Price price = getFirstPrice(updatedProduct); assertThat(price.getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a value"); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); final Product updated2 = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, SetProductPriceCustomField.ofObject(STRING_FIELD_NAME, "a new value", priceId, staged))); assertThat(getFirstPrice(updated2).getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a new value"); assertThat(updated2.getMasterData().hasStagedChanges()).isEqualTo(staged); return updated2; }); return type; }); }
@Test public void setProductPriceCustomTypeAndsetProductPriceCustomField() { withUpdateableType(client(), type -> { withUpdateablePricedProduct(client(), product -> { final String priceId = getFirstPrice(product).getId(); final UpdateAction<Product> updateAction = SetProductPriceCustomType. ofTypeIdAndObjects(type.getId(), STRING_FIELD_NAME, "a value", priceId); final ProductUpdateCommand productUpdateCommand = ProductUpdateCommand.of(product, updateAction); final Product updatedProduct = client().executeBlocking(productUpdateCommand); final Price price = getFirstPrice(updatedProduct); assertThat(price.getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a value"); final Product updated2 = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, SetProductPriceCustomField.ofObject(STRING_FIELD_NAME, "a new value", priceId))); assertThat(getFirstPrice(updated2).getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a new value"); return updated2; }); return type; }); }
assertThat(lineItem.getQuantity()).isEqualTo(2); assertThat(lineItem.getName()).isEqualTo(name); assertThat(lineItem.getPrice().getCustom()).isNotNull();
@Test public void createProductWithCustomPrice() { withEmptyProductType(client(), randomKey(), productType -> withUpdateableType(client(), type -> { final String value = "foo"; final PriceDraft price = PriceDraft.of(EURO_1) .withCustom(CustomFieldsDraft.ofTypeIdAndObjects(type.getId(), singletonMap(STRING_FIELD_NAME, value))); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().price(price).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.getCustom().getFieldAsString(STRING_FIELD_NAME)).isEqualTo(value); client().executeBlocking(ProductDeleteCommand.of(product)); return type; }) ); }