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())); }
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; }); }
@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; }); }
@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; }); }
@Test public void publishWithAllScope() 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.ALL) ); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, updateActions)); List<Price> prices = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); assertThat(expectedPrice).isEqualTo(PriceDraft.of(prices.get(0))); assertThat(updatedProduct.getMasterData().getCurrent().getMasterVariant().getImages()).isEqualTo(asList(image)); 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; }); }
private static void withTaxedAndPricedProduct(final BlockingSphereClient client, final long centAmount, final double taxRate, final boolean taxIncluded, final Consumer<Product> operator) { final List<TaxRateDraft> taxRateDrafts = singletonList(TaxRateDraftBuilder.of(randomKey(), taxRate, taxIncluded, CountryCode.DE).build()); final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraft.of(randomString(), taxRateDrafts); withTaxCategory(client, taxCategoryDraft, taxCategory -> withProduct(client, product -> { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.ofCents(centAmount, EUR)).withCountry(DE); final ProductUpdateCommand setPricesCmd = ProductUpdateCommand.of(product, asList( AddPrice.of(MASTER_VARIANT_ID, priceDraft), SetTaxCategory.of(taxCategory), Publish.of())); final Product productWithPrice = client.executeBlocking(setPricesCmd); operator.accept(productWithPrice); }) ); } }
@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); }