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

io.sphere.sdk.products.queries.ProductQuery Maven / Gradle / Ivy

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

import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.models.Referenceable;
import io.sphere.sdk.products.Product;
import io.sphere.sdk.products.ProductProjectionType;
import io.sphere.sdk.products.expansion.ProductExpansionModel;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.queries.*;

import java.util.Locale;

/**
 {@doc.gen summary products}
 */
public interface ProductQuery extends MetaModelQueryDsl> {

    static TypeReference> resultTypeReference() {
        return new TypeReference>(){
            @Override
            public String toString() {
                return "TypeReference>";
            }
        };
    }

    static ProductQuery of() {
        return new ProductQueryImpl();
    }

    default ProductQuery bySlug(final ProductProjectionType type, final Locale locale, final String slug) {
        return withPredicates(m -> m.masterData().forProjection(type).slug().lang(locale).is(slug));
    }

    default ProductQuery byProductType(final Referenceable productType) {
        return withPredicates(m -> m.productType().is(productType));
    }

    default ProductQuery bySku(final String sku, final ProductProjectionType type) {
        final QueryPredicate skuPredicate = PartialProductVariantQueryModel.of().sku().is(sku);
        final ProductDataQueryModel projection = ProductQueryModel.of().masterData().forProjection(type);
        final QueryPredicate masterVariantSkuPredicate = projection.masterVariant().where(skuPredicate);
        final QueryPredicate variantsSkuPredicate = projection.variants().where(skuPredicate);
        return withPredicates(masterVariantSkuPredicate.or(variantsSkuPredicate));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy