public static AddPrice of(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price); }
public static AddPrice ofVariantId(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price, null); }
public static AddPrice of(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price); }
public static AddPrice ofVariantId(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price, null); }
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 addPriceByVariantId() throws Exception { 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))); 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()).isTrue(); return updatedProduct; }); }
public void removePriceWithStaged(final Boolean staged) { 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 Price oldPrice = getFirstPrice(productWithPrice); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(productWithPrice, RemovePrice.of(oldPrice, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant() .getPrices().stream().anyMatch(p -> p.equals(oldPrice))).isFalse(); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void changePriceWithStaged(final Boolean staged) { 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 PriceDraft newPrice = PriceDraft.of(MoneyImpl.of(234, EUR)); final List<Price> prices = productWithPrice.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(productWithPrice, ChangePrice.of(prices.get(0), newPrice, staged))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newPrice); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
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; }); }