All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.products.ProductDraftBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.products;

import io.sphere.sdk.models.*;
import io.sphere.sdk.producttypes.ProductType;

import java.util.Collections;
import java.util.List;

public final class ProductDraftBuilder extends ProductDataProductDraftBuilderBase implements Builder {

    private final Reference productType;
    private ProductVariantDraft masterVariant;
    private List variants = Collections.emptyList();

    private ProductDraftBuilder(final Reference productType, final LocalizedString name, final LocalizedString slug, final ProductVariantDraft masterVariant) {
        super(name, slug);
        this.productType = productType;
        this.masterVariant = masterVariant;
    }

    public static ProductDraftBuilder of(final Referenceable productType, final LocalizedString name, final LocalizedString slug, final ProductVariantDraft masterVariant) {
        return new ProductDraftBuilder(productType.toReference(), name, slug, masterVariant);
    }

    @Override
    public ProductDraft build() {
        return new ProductDraftImpl(productType, getName(), getSlug(), getDescription(), getCategories(), MetaAttributes.metaAttributesOf(getMetaTitle(), getMetaDescription(), getMetaKeywords()), masterVariant, variants, getTaxCategory(), getSearchKeywords(), getState(), getCategoryOrderHints());
    }

    @Override
    protected ProductDraftBuilder getThis() {
        return this;
    }

    public ProductDraftBuilder variants(final List variants) {
        this.variants = variants;
        return getThis();
    }

    public ProductDraftBuilder masterVariant(final ProductVariantDraft masterVariant) {
        this.masterVariant = masterVariant;
        return getThis();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy