public static AddPrice of(final long variantId, final Price price, final ProductUpdateScope productUpdateScope) { return new AddPrice(variantId, price, productUpdateScope); } }
public static AddPrice ofSku(final String sku, final PriceDraft price) { return ofSku(sku, price, null); }
public static AddPrice ofVariantId(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price, null); }
public static void withUpdateablePricedProduct(final BlockingSphereClient client, final PriceDraft expectedPrice, final Function<Product, Product> f) { withUpdateableProduct(client, product -> { final ProductUpdateCommand command = ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice)); return f.apply(client.executeBlocking(command)); }); }
private static ProductUpdateCommand createSetTaxesCommand(final TaxCategory taxCategory, final Product product) { return ProductUpdateCommand.of(product, asList(AddPrice.of(MASTER_VARIANT_ID, PRICE), SetTaxCategory.of(taxCategory), Publish.of())); }
public static AddPrice of(final Integer variantId, final PriceDraft price) { return new AddPrice(variantId, price); } }
public static AddPrice of(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price); }
public static AddPrice ofSku(final String sku, final PriceDraft price) { return ofSku(sku, price, null); }
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; }); }
public static AddPrice of(final int variantId, final Price price, final ProductUpdateScope productUpdateScope) { return new AddPrice(variantId, price, productUpdateScope); } }
public static AddPrice of(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price); }
public void addPriceBySkuWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofSku(sku, 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 addPrice() throws Exception { final PriceDraft expectedPrice = PriceDraft.of(MoneyImpl.of(123, EUR)); 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; }); }
public static AddPrice ofSku(final String sku, final PriceDraft price, @Nullable final Boolean staged) { return new AddPrice(null, sku, price, staged); } }
public static AddPrice ofVariantId(final Integer variantId, final PriceDraft price) { return ofVariantId(variantId, price, null); }
@Test public void addPriceBySku() throws Exception { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofSku(sku, 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; }); }
@Test public void addPriceWithTiers() throws Exception { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_1).build(), PriceTierBuilder.of(5, EURO_5).build()); final PriceDraft expectedPriceWithTiers = PriceDraftBuilder.of(MoneyImpl.of(123, EUR)) .tiers(tiers) .build(); withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPriceWithTiers))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPriceWithTiers).isEqualTo(PriceDraft.of(actualPrice)); return updatedProduct; }); }
public static AddPrice ofSku(final String sku, final PriceDraft price, @Nullable final Boolean staged) { return new AddPrice(null, sku, price, staged); } }
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 publishWithPriceScope() throws Exception { withUpdateableProduct(client(), (Product product) -> { final ProductData stagedData = product.getMasterData().getStaged(); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final ProductData currentData = publishedProduct.getMasterData().getCurrent(); assertThat(stagedData.getMasterVariant().getImages()).hasSize(0); assertThat(stagedData.getMasterVariant().getPrices()).hasSize(0); assertThat(currentData).isEqualTo(stagedData); final PriceDraft expectedPrice = PriceDraft.of(EURO_10); final Image image = createExternalImage(); final List<UpdateAction<Product>> updateActions = asList( AddExternalImage.of(image, MASTER_VARIANT_ID), AddPrice.of(MASTER_VARIANT_ID, expectedPrice), Publish.ofScope(PublishScope.PRICES) ); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, updateActions)); List<Price> prices = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices(); //Verify published price in the current product assertThat(prices).hasSize(1); assertThat(expectedPrice).isEqualTo(PriceDraft.of(prices.get(0))); //Verify that the image has not been published assertThat(updatedProduct.getMasterData().getCurrent().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }