default ProductProjectionQuery byProductType(final Referenceable<ProductType> productType) { return withPredicates(m -> m.productType().is(productType)); }
public static ProductProjectionQueryModel of() { return new ProductProjectionQueryModel(null, null); }
private ProductProjectionQueryModel model() { return ProductProjectionQueryModel.of(); }
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
@Test public void allVariantsInProductProjection() throws Exception { assertThat(ProductProjectionQueryModel.of().allVariants().where(m -> m.sku().is("bar"))) .isEqualTo(ProductProjectionQueryModel.of().where(m -> m.masterVariant().sku().is("bar").or(m.variants().sku().is("bar")))) .isEqualTo(QueryPredicate.<ProductProjection>of(embeddedProductProjectionPredicate)); } }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
public QueryPredicate<ProductProjection> is(final Referenceable<Product> product) { return id().is(product.toReference().getId()); } }
private static List<ProductProjection> queryForCategoryAndSort(final String categoryId) { final ProductProjectionQuery query = ProductProjectionQuery.ofStaged() .withPredicates(productModel -> productModel.categories().id().is(categoryId)) .withSort(productModel -> productModel.categoryOrderHints().category(categoryId).asc()); return client().executeBlocking(query).getResults(); }
public static ProductProjectionQueryModel model() { return ProductProjectionQueryModel.get(); }
withProductInCategory(client(), jeansCategory, jeansProduct -> { withProductInCategory(client(), tshirtCategory, tshirtProduct -> { final ProductProjectionQuery sphereRequest = ProductProjectionQuery.ofStaged().withPredicates(m -> m.categories().isIn(asList(mensClothingCategory))); final PagedQueryResult<ProductProjection> resultForParentCategory = .isEmpty(); final ProductProjectionQuery query = ProductProjectionQuery.ofStaged().withPredicates(m -> m.categories().isIn(asList(tshirtCategory, jeansCategory))); assertThat(query.predicates().get(0)) .isEqualTo(QueryPredicate.of(format("categories(id in (\"%s\", \"%s\"))", tshirtCategory.getId(), jeansCategory.getId())));
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
private static QueryResult doQuery() { List<ProductProjection> sortedFromSearchForCategory1 = searchForCategoryAndSort(category1Id); List<ProductProjection> sortedFromQueryForCategory1 = queryForCategoryAndSort(category1Id); List<ProductProjection> sortedFromSearchForCategory2 = searchForCategoryAndSort(category2Id); List<ProductProjection> sortedFromQueryForCategory2 = queryForCategoryAndSort(category2Id); final List<String> ids = products.stream().map(p -> p.getId()).collect(toList()); final ProductProjectionQuery productProjectionQuery = ProductProjectionQuery.ofStaged() .withPredicates(productModel -> productModel.id().isIn(ids)); List<ProductProjection> productProjections = client().executeBlocking(productProjectionQuery).getResults(); return new QueryResult(productProjections, sortedFromSearchForCategory1, sortedFromSearchForCategory2, sortedFromQueryForCategory1, sortedFromQueryForCategory2); }
public static ProductProjectionQueryModel model() { return ProductProjectionQueryModel.get(); }
@Test public void queryByCategory() throws Exception { withCategory(client(), cat3 -> withCategory(client(), cat1 -> withCategory(client(), cat2 -> with2products("queryByCategory", (p1, p2) -> { final Category cat1WithParent = client().executeBlocking(CategoryUpdateCommand.of(cat1, asList(ChangeParent.of(cat3)))); final Product productWithCat1 = client().executeBlocking(ProductUpdateCommand.of(p1, AddToCategory.of(cat1WithParent))); final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.categories().isIn(asList(cat1, cat2))) .withExpansionPaths(m -> m.categories().parent()); final PagedQueryResult<ProductProjection> queryResult = client().executeBlocking(query); assertThat(ids(queryResult)).containsOnly(productWithCat1.getId()); final Reference<Category> cat1Loaded = queryResult.head().get().getCategories().stream().findAny().get(); assertThat(cat1Loaded).as("cat of product is expanded").is(expanded()); final Reference<Category> parent = cat1Loaded.getObj().getParent(); assertThat(parent).as("parent of cat is expanded").is(expanded()); }) ) ) ); }
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
default ProductProjectionQuery byProductType(final Referenceable<ProductType> productType) { return withPredicates(m -> m.productType().is(productType)); }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
@Test public void expandChannelInPrice() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().channel()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
ProductProjectionQueryImpl(final ProductProjectionType productProjectionType){ super(ProductProjectionEndpoint.ENDPOINT.endpoint(), ProductProjectionQuery.resultTypeReference(), ProductProjectionQueryModel.of(), ProductProjectionExpansionModel.of(), ProductProjectionQueryImpl::new, additionalParametersOf(productProjectionType)); }