Codota Logo
ProductData.getMasterVariant
Code IndexAdd Codota to your IDE (free)

How to use
getMasterVariant
method
in
io.sphere.sdk.products.ProductData

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeGetValueAs() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final String attributeValue = masterVariant.findAttribute(SIZE_ATTR_NAME)
      .map((Attribute a) -> {
        final EnumValue enumValue = a.getValueAsEnumValue();
        return enumValue.getLabel();
      })
      .orElse("not found");
  assertThat(attributeValue).isEqualTo("S");
}
origin: commercetools/commercetools-jvm-sdk

public static void withProductOfRestockableInDaysAndChannel(final BlockingSphereClient client, final int restockableInDays, @Nullable final Referenceable<Channel> channelReferenceable, final Consumer<Product> productConsumer) {
  final Reference<Channel> channelReference = Optional.ofNullable(channelReferenceable).map(Referenceable::toReference).orElse(null);
  ProductFixtures.withProduct(client, product -> {
    final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
    final InventoryEntry inventoryEntry = client.executeBlocking(InventoryEntryCreateCommand.of(InventoryEntryDraft.of(sku, 5, null, restockableInDays, channelReference)));
    productConsumer.accept(product);
    client.executeBlocking(InventoryEntryDeleteCommand.of(inventoryEntry));
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeWithoutProductTypeWithNamedAccessWithWrongType() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  assertThatThrownBy(() -> masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofBoolean()))
      .isInstanceOf(JsonException.class);
}
origin: commercetools/commercetools-jvm-sdk

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;
  });
}
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 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

@Test
public void variantIdentifierIsAvailable() throws Exception {
  withProduct(client(), product -> {
    final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier();
    assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1));
  });
}
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 notPresentAttributeRead() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Optional<Boolean> attributeOption = masterVariant.findAttribute("notpresent", AttributeAccess.ofBoolean());
  assertThat(attributeOption).isEmpty();
}
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 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 readAttributeWithoutProductTypeWithName() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Optional<EnumValue> attributeOption =
      masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofEnumValue());
  assertThat(attributeOption).contains(EnumValue.of("S", "S"));
}
origin: commercetools/commercetools-jvm-sdk

@BeforeClass
public static void setupScenario() {
  data = ProductsScenario1Fixtures.createScenario(client());
  masterVariant = data.getProduct1().getMasterData().getStaged().getMasterVariant();
}
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 readAttributeWithoutProductTypeWithNamedAccess() throws Exception {
  final NamedAttributeAccess<EnumValue> size = AttributeAccess.ofEnumValue().ofName(SIZE_ATTR_NAME);
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Optional<EnumValue> attributeOption = masterVariant.findAttribute(size);
  assertThat(attributeOption).contains(EnumValue.of("S", "S"));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeWithoutProductTypeWithJson() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Attribute attr = masterVariant.getAttribute(SIZE_ATTR_NAME);
  final JsonNode expectedJsonNode = SphereJsonUtils.toJsonNode(EnumValue.of("S", "S"));
  assertThat(attr.getValue(AttributeAccess.ofJsonNode())).isEqualTo(expectedJsonNode);
}
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 selectAPriceByCurrencyInProductByIdGet() {
  final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20));
  withProductOfPrices(prices, product -> {
    final ProductByIdGet request = ProductByIdGet.of(product)
        .withPriceSelection(PriceSelection.of(EUR));//price selection config
    final Product result = client().executeBlocking(request);
    final ProductVariant masterVariant = result.getMasterData().getStaged().getMasterVariant();
    assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30)));
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void selectAPriceByCurrencyInProductUpdateCommand() {
  ProductFixtures.withProduct(client(), product -> {
    final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20));
    final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetPrices.of(1, prices))
        .withPriceSelection(PriceSelection.of(EUR));
    final Product updatedProduct = client().executeBlocking(cmd);
    final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant();
    assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30)));
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test(expected = NotFoundException.class)
public void executeInvalidQuery(){
  withUpdateableProductDiscount(client(),((productDiscount, product) -> {
      final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant();
      final Price invalidPice = Price.of(MoneyImpl.of(0, DefaultCurrencyUnits.USD));
      final ProductDiscount queryedProductDiscount = client().executeBlocking(MatchingProductDiscountGet.of(product.getId(), masterVariant.getId(), true, invalidPice));
      return productDiscount;
  }));
}
io.sphere.sdk.productsProductDatagetMasterVariant

Popular methods of ProductData

  • getCategories
  • getDescription
  • getMetaDescription
  • getMetaKeywords
  • getMetaTitle
  • getName
  • getSlug
  • getVariants
  • getSearchKeywords
  • getCategoryOrderHints
  • getAllVariants
  • getAllVariants

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • orElseThrow (Optional)
  • getSystemService (Context)
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Iterator (java.util)
    An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Frame
  • Set (java.util)
    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now