/** * Creates a new builder with the values of this object. * * @return new builder */ public ProductDraftBuilder newBuilder() { return new ProductDraftBuilder(categories, categoryOrderHints, description, key, masterVariant, metaDescription, metaKeywords, metaTitle, name, productType, publish, searchKeywords, slug, state, taxCategory, variants); }
public ProductDraftDsl withCategories(final Set<ResourceIdentifier<Category>> categories) { return newBuilder().categories(categories).build(); }
@Override public ProductDraft build() { return new ProductDraftImpl(productType, getName(), getSlug(), getDescription(), getCategories(), getMetaTitle(), getMetaDescription(), getMetaKeywords(), masterVariant, variants, getTaxCategory(), getSearchKeywords(), getState(), getCategoryOrderHints()); }
@Override public ProductDraft build() { return new ProductDraftImpl(productType, getName(), getSlug(), getDescription(), getCategories(), MetaAttributes.metaAttributesOf(getMetaTitle(), getMetaDescription(), getMetaKeywords()), masterVariant, variants); }
final CategoryOrderHints categoryOrderHints = CategoryOrderHints.of("category-id", "5"); final String key = randomKey(); final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, name, slug, masterVariant) .description(description) .metaTitle(metaTitle) .metaDescription(metaDescription) .metaKeywords(metaKeywords) .categories(categories) .taxCategory(taxCategory) .searchKeywords(searchKeywords) .state(state) .categoryOrderHints(categoryOrderHints) .publish(true) .key(key); final ProductDraft productDraft = productDraftBuilder.build(); assertThat(productDraft.getName()).isEqualTo(name); assertThat(productDraft.getSlug()).isEqualTo(slug); assertThat(productDraft.isPublish()).isTrue(); assertThat(productDraft.getKey()).isEqualTo(key); assertThat(ProductDraftBuilder.of(productDraft)).isEqualTo(productDraftBuilder);
@Test public void createsWithAllVariants() { final List<ProductVariantDraft> allVariants = IntStream.range(0, 9) .mapToObj(i -> ProductVariantDraftBuilder.of().sku("sku-" + i).build()) .collect(toList()); final Reference<ProductType> productType = ProductType.referenceOfId("product-type-id"); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), allVariants).build(); assertThat(productDraft.getMasterVariant().getSku()).isEqualTo("sku-0"); assertThat(productDraft.getVariants().get(3).getSku()).isEqualTo("sku-4"); }
@Override public ProductDraft get() { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .attributes(Sizes.ATTRIBUTE.draftOf(Sizes.S), Colors.ATTRIBUTE.draftOf(Colors.GREEN)) .sku(UUID.randomUUID().toString()) .build(); final LocalizedString slug = en(name).slugifiedUnique(); return ProductDraftBuilder.of(productType, en(name), slug, masterVariant) .description(en(name)) .metaTitle(en("cotton t-shirt")) .metaDescription(en("cotton t-shirt description")) .metaKeywords(en("cotton, t-shirt, clothes")) .build(); }
private void withProductOfPrices(final List<PriceDraft> priceDrafts, final Consumer<Product> productConsumer) { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .prices(priceDrafts) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant) .key(randomKey()) .build(); ProductFixtures.withProduct(client(), () -> productDraft, productConsumer); } }
@Test public void createProductWithExternalImage() throws Exception { withStateByBuilder(client(), stateBuilder -> stateBuilder.initial(true).type(PRODUCT_STATE), initialProductState -> { final ProductType productType = ProductTypeFixtures.defaultProductType(client()); final Image image = Image.ofWidthAndHeight("http://www.commercetools.com/assets/img/ct_logo_farbe.gif", 460, 102, "commercetools logo"); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .images(image) .build(); final TaxCategory taxCategory = defaultTaxCategory(client()); final SearchKeywords searchKeywords = SearchKeywords.of(Locale.ENGLISH, asList(SearchKeyword.of("foo bar baz", CustomSuggestTokenizer.of(asList("foo, baz"))))); final ProductDraft productDraft = ProductDraftBuilder .of(productType, en("product with external image"), randomSlug(), masterVariant) .taxCategory(taxCategory) .searchKeywords(searchKeywords) .state(initialProductState) .build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Image loadedImage = product.getMasterData().getStaged().getMasterVariant().getImages().get(0); assertThat(loadedImage).isEqualTo(image); assertThat(product.getTaxCategory()).isEqualTo(taxCategory.toReference()); assertThat(product.getMasterData().getStaged().getSearchKeywords()).isEqualTo(searchKeywords); assertThat(product.getState()).isEqualTo(initialProductState.toReference()); //clean up test client().executeBlocking(ProductDeleteCommand.of(product)); }); }
private void withProductOfPrices(final List<PriceDraft> priceDrafts, final Consumer<Product> productConsumer) { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .prices(priceDrafts) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant) .publish(true) .build(); withProduct(client(), () -> productDraft, productConsumer); } }
final ProductVariantDraft masterVariantDraft = ProductVariantDraftBuilder.of().build(); final CategoryOrderHints categoryOrderHints = orderHints != null ? CategoryOrderHints.of(orderHints) : null; final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariantDraft) .categoryOrderHints(categoryOrderHints) .categories(asList(category1.toReference(), category2.toReference())) .build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); return product;
private static Product createTestProduct(final ProductType productType, final String germanName, final String englishName, final String color, final int size1, final int size2, final String sku, final String slug) { final LocalizedString name = LocalizedString.of(GERMAN, germanName, ENGLISH, englishName); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .attributes(AttributeDraft.of(ATTR_NAME_SIZE, size1), AttributeDraft.of(ATTR_NAME_COLOR, color)) .price(PriceDraft.of(new BigDecimal("23.45"), EUR)) .sku(sku) .key(slug + "-master-variant-key") .build(); final ProductVariantDraft variant = ProductVariantDraftBuilder.of() .attributes(AttributeDraft.of(ATTR_NAME_SIZE, size2)) .price(PriceDraft.of(new BigDecimal("27.45"), EUR)) .key(slug + "-variant2-key") .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, name, LocalizedString.of(ENGLISH, slug), masterVariant) .plusVariants(variant) .key(slug + "-product-key") .build(); return client().executeBlocking(ProductCreateCommand.of(productDraft)); }
private static void withProductInCategory(final BlockingSphereClient client, final Referenceable<Category> category, final Consumer<Product> user) { final ProductType productType = client.executeBlocking(ProductTypeCreateCommand.of(ProductTypeDraft.of(randomKey(), CategoryDocumentationIntegrationTest.class.getSimpleName(), "", asList()))); final LocalizedString name = LocalizedString.of(ENGLISH, "foo"); final Product product = client.executeBlocking(ProductCreateCommand.of(ProductDraftBuilder.of(productType, name, name.slugifiedUnique(), ProductVariantDraftBuilder.of().build()).categories(asSet(category.toReference())).build())); user.accept(product); client.executeBlocking(ProductDeleteCommand.of(product)); client.executeBlocking(ProductTypeDeleteCommand.of(productType)); }
public static void withUpdateableProductOfMultipleVariants(final BlockingSphereClient client, final Function<Product, Versioned<Product>> f) { withProductType(client, randomKey(), productType -> { final AttributeDraft greenColor = AttributeDraft.of(TShirtProductTypeDraftSupplier.Colors.ATTRIBUTE, TShirtProductTypeDraftSupplier.Colors.GREEN); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .attributes(AttributeDraft.of(TShirtProductTypeDraftSupplier.Sizes.ATTRIBUTE, TShirtProductTypeDraftSupplier.Sizes.M), greenColor) .sku(randomKey()) .build(); final List<ProductVariantDraft> variants = Stream.of(TShirtProductTypeDraftSupplier.Sizes.S, TShirtProductTypeDraftSupplier.Sizes.X) .map(size -> AttributeDraft.of(TShirtProductTypeDraftSupplier.Sizes.ATTRIBUTE, size)) .map(attrDraft -> ProductVariantDraftBuilder.of() .attributes(attrDraft, greenColor) .sku(randomKey()) .build()) .collect(toList()); final ProductDraftBuilder builder = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant) .variants(variants); final ProductDraft productDraft = builder.build(); final Product product = client.executeBlocking(ProductCreateCommand.of(productDraft)); Versioned<Product> productToDelete = f.apply(product); client.executeBlocking(ProductDeleteCommand.of(productToDelete)); }); }
public ProductDraftBuilder categories(final List<Reference<Category>> categories) { return categories(new LinkedHashSet<>(categories)); }
public ProductDraftDsl withSearchKeywords(final SearchKeywords searchKeywords) { return newBuilder().searchKeywords(searchKeywords).build(); }
public ProductDraftDsl withMetaKeywords(@Nullable final LocalizedString metaKeywords) { return newBuilder().metaKeywords(metaKeywords).build(); }