Tabnine Logo
ProductData.getMasterVariant
Code IndexAdd Tabnine 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)

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

  • Making http requests using okhttp
  • addToBackStack (FragmentTransaction)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (Timer)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • String (java.lang)
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Option (scala)
  • Github Copilot alternatives
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