Tabnine Logo
ProductUpdateCommand.of
Code IndexAdd Tabnine to your IDE (free)

How to use
of
method
in
io.sphere.sdk.products.commands.ProductUpdateCommand

Best Java code snippets using io.sphere.sdk.products.commands.ProductUpdateCommand.of (Showing top 20 results out of 315)

origin: commercetools/commercetools-jvm-sdk

public static void withProductInCategory(final BlockingSphereClient client, final BiConsumer<Product, Category> consumer) {
  withCategory(client, category -> {
    final Consumer<Product> user = product -> consumer.accept(product, category);
    withProduct(client, "withProductAndCategory", product -> {
      final Product productWithCategory = client.executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category)));
      consumer.accept(productWithCategory, category);
    });
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void publish() throws Exception {
  withUpdateableProduct(client(), product -> {
    assertThat(product.getMasterData().isPublished()).isFalse();
    final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of()));
    assertThat(publishedProduct.getMasterData().isPublished()).isTrue();
    final Product unpublishedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, Unpublish.of()));
    assertThat(unpublishedProduct.getMasterData().isPublished()).isFalse();
    return unpublishedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

public void changeSlugWithStaged(final Boolean staged) {
  withUpdateableProduct(client(), product -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final LocalizedString newSlug = LocalizedString.ofEnglish("new-slug-" + RANDOM.nextInt());
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeSlug.of(newSlug, staged)));
    assertThat(updatedProduct.getMasterData().getStaged().getSlug()).isEqualTo(newSlug);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

public void setDescriptionWithStaged(final Boolean staged) {
  withUpdateableProduct(client(), product -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final LocalizedString newDescription = LocalizedString.ofEnglish("new description " + RANDOM.nextInt());
    final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetDescription.of(newDescription, staged));
    final Product updatedProduct = client().executeBlocking(cmd);
    assertThat(updatedProduct.getMasterData().getStaged().getDescription()).isEqualTo(newDescription);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void removePrice() throws Exception {
  withUpdateablePricedProduct(client(), product -> {
    final Price oldPrice = getFirstPrice(product);
    final Product updatedProduct = client()
        .executeBlocking(ProductUpdateCommand.of(product, RemovePrice.of(oldPrice)));
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant()
        .getPrices().stream().anyMatch(p -> p.equals(oldPrice))).isFalse();
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

public void changeNameWithStaged(final Boolean staged) {
  withUpdateableProduct(client(), product -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt());
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(newName, staged)));
    assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

public void setSearchKeywordsWithStaged(final Boolean staged) {
  withUpdateableProduct(client(), product -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final SearchKeywords searchKeywords = SearchKeywords.of(Locale.ENGLISH, asList(SearchKeyword.of("Raider", CustomSuggestTokenizer.of(singletonList("Twix")))));
    final ProductUpdateCommand command = ProductUpdateCommand.of(product, SetSearchKeywords.of(searchKeywords, staged));
    final Product updatedProduct = client().executeBlocking(command);
    final SearchKeywords actualKeywords = updatedProduct.getMasterData().getStaged().getSearchKeywords();
    assertThat(actualKeywords).isEqualTo(searchKeywords);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setKey() throws Exception {
  final String key = randomKey();
  withProduct(client(), (Product product) -> {
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetKey.of(key)));
    assertThat(updatedProduct.getKey()).isEqualTo(key);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void updateWithWrongType() throws Exception {
  final Product product = createProduct();
  assertThatThrownBy(() -> client().executeBlocking(ProductUpdateCommand.of(product,
      SetAttribute.of(1, AttributeDraft.of(LAUNDRY_SYMBOLS_ATTR_NAME, "cold")))))
      .isInstanceOf(ErrorResponseException.class)
      .matches(e -> ((ErrorResponseException)e).hasErrorCode(InvalidField.CODE));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setDescription() throws Exception {
  withUpdateableProduct(client(), product -> {
    final LocalizedString newDescription = LocalizedString.ofEnglish("new description " + RANDOM.nextInt());
    final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetDescription.of(newDescription));
    final Product updatedProduct = client().executeBlocking(cmd);
    assertThat(updatedProduct.getMasterData().getStaged().getDescription()).isEqualTo(newDescription);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setPricesEmptyList() {
  withUpdateablePricedProduct(client(), product -> {
    final Product updatedProduct = client()
        .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, emptyList())));
    final List<Price> newPrices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices();
    assertThat(newPrices).isEmpty();
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setTaxCategory() throws Exception {
  TaxCategoryFixtures.withTransientTaxCategory(client(), taxCategory ->
      withUpdateableProduct(client(), product -> {
        assertThat(product.getTaxCategory()).isNotEqualTo(taxCategory);
        final ProductUpdateCommand command = ProductUpdateCommand.of(product, SetTaxCategory.of(taxCategory));
        final Product updatedProduct = client().executeBlocking(command);
        assertThat(updatedProduct.getTaxCategory()).isEqualTo(taxCategory.toReference());
        return updatedProduct;
      })
  );
}
origin: commercetools/commercetools-jvm-sdk

public void setProductVariantKeyByVariantIdWithStaged(final Boolean staged) {
  final String key = randomKey();
  withProduct(client(), (Product product) -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final Integer variantId = product.getMasterData().getStaged().getMasterVariant().getId();
    final ProductUpdateCommand cmd =
        ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndVariantId(key, variantId, staged));
    final Product updatedProduct = client().executeBlocking(cmd);
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
  });
}
origin: commercetools/commercetools-jvm-sdk

public void setProductVariantKeyBySkuWithStaged(final Boolean staged) {
  final String key = randomKey();
  withProduct(client(), (Product product) -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
    final ProductUpdateCommand cmd =
        ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndSku(key, sku, staged));
    final Product updatedProduct = client().executeBlocking(cmd);
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key);
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setCategoryOrderHint() throws Exception {
  withProductInCategory(client(), (product, category) -> {
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetCategoryOrderHint.of(category.getId(), "0.1234")));
    final CategoryOrderHints actual = updatedProduct.getMasterData().getStaged().getCategoryOrderHints();
    assertThat(actual).isEqualTo(CategoryOrderHints.of(category.getId(), "0.1234"));
    assertThat(actual.getAsMap()).isEqualTo(Collections.singletonMap(category.getId(), "0.1234"));
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void removeImageByVariantId() throws Exception {
  final Image image = createExternalImage();
  withUpdateableProduct(client(), product -> {
    final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image)));
    assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image));
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofVariantId(MASTER_VARIANT_ID, image)));
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void removeImageBySku() throws Exception {
  final Image image = createExternalImage();
  withUpdateableProduct(client(), product -> {
    final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
    final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(sku, image)));
    assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image));
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofSku(sku, image)));
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0);
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addExternalImage() throws Exception {
  withUpdateableProduct(client(), (Product product) -> {
    assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0);
    final Image image = createExternalImage();
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.of(image, MASTER_VARIANT_ID)));
    assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image));
    return updatedProduct;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void updateAttributesBooks() throws Exception {
  final Product product = createBookProduct();
  final int masterVariantId = 1;
  final AttributeDraft attributeDraft = AttributeDraft.of(ISBN_ATTR_NAME, "978-3-86680-192-8");
  final SetAttribute updateAction = SetAttribute.of(masterVariantId, attributeDraft);
  final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, updateAction));
  final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant();
  assertThat(masterVariant.findAttribute(ISBN_ATTR_NAME, AttributeAccess.ofText()))
      .contains("978-3-86680-192-8");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryBySku() throws Exception {
  withProduct(client(), product -> {
    final String sku = "sku-" + randomString();
    final Product productWithSku = client().executeBlocking(ProductUpdateCommand.of(product, SetSku.of(MASTER_VARIANT_ID, sku)));
    final QueryPredicate<ProductProjection> predicate = model().masterVariant().sku().is(sku);
    checkOneResult(productWithSku, predicate);
  });
}
io.sphere.sdk.products.commandsProductUpdateCommandof

Popular methods of ProductUpdateCommand

  • ofKey
  • <init>
  • getUpdateActions
  • plusUpdateActions
  • withPriceSelection

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • ImageIO (javax.imageio)
  • JTable (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now