default ProductProjectionQuery byProductType(final Referenceable<ProductType> productType) { return withPredicates(m -> m.productType().is(productType)); }
default ProductProjectionQuery byProductType(final Referenceable<ProductType> productType) { return withPredicates(m -> m.productType().is(productType)); }
default ProductProjectionQuery byProductType(final Referenceable<ProductType> productType) { return withPredicates(m -> m.productType().is(productType)); }
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
default ProductProjectionQuery bySlug(final Locale locale, final String slug) { return withPredicates(m -> m.slug().lang(locale).is(slug)); }
default ProductProjectionQuery bySku(final List<String> skus) { return withPredicates(m -> m.allVariants().where(n -> n.sku().isIn(skus))); }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
default ProductProjectionQuery bySku(final List<String> skus) { return withPredicates(m -> m.allVariants().where(n -> n.sku().isIn(skus))); }
default ProductProjectionQuery bySku(final String sku) { return withPredicates(m -> m.allVariants().where(n -> n.sku().is(sku))); }
private void checkOneResult(final Product product, final QueryPredicate<ProductProjection> predicate) { final PagedQueryResult<ProductProjection> queryResult = client().executeBlocking(ProductProjectionQuery.of(STAGED).withPredicates(predicate)); assertThat(ids(queryResult)).containsOnly(product.getId()); }
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); }
@Test public void variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())); final ProductProjection productProjection = client().executeBlocking(query).head().get(); final ByIdVariantIdentifier identifier = productProjection.getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@Test public void queryById() throws Exception { with2products("queryById", (p1, p2) -> { final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().isIn(asList(p1.getId(), p2.getId()))); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId(), p2.getId()); final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(p1.getId())); assertThat(ids(client().executeBlocking(query))).containsOnly(p1.getId()); }); }
@Test public void selectAPriceByCurrencyInProductProjectionQuery() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionQuery request = ProductProjectionQuery.ofStaged() .withPredicates(m -> m.id().is(product.getId()))//to limit the test scope .withPriceSelection(PriceSelection.of(EUR));//price selection config final PagedQueryResult<ProductProjection> result = client().executeBlocking(request); assertThat(result.getCount()).isEqualTo(1); final ProductVariant masterVariant = result.getResults().get(0).getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void differentiateBetweenCurrentAndStaged() throws Exception { withUpdateableProduct(client(), product -> { final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final Product mixedDataProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, ChangeName.of(randomSlug()))); final LocalizedString nameInCurrent = mixedDataProduct.getMasterData().getCurrent().getName(); final LocalizedString nameInStaged = mixedDataProduct.getMasterData().getStaged().getName(); final ProductProjectionQuery stagedQuery = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(stagedQuery).head().get().getName()).isEqualTo(nameInStaged); final ProductProjectionQuery currentQuery = ProductProjectionQuery.of(CURRENT).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(currentQuery).head().get().getName()).isEqualTo(nameInCurrent); return mixedDataProduct; }); }
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(); }
@Test public void queryByHasStagedChanges() throws Exception { withProduct(client(), product -> { final Product updated = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(randomSlug()))); final ProductProjectionQuery query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.hasStagedChanges().is(true)) .withSort(m -> m.createdAt().sort().desc()); final PagedQueryResult<ProductProjection> pagedQueryResult = client().executeBlocking(query); assertThat(ids(pagedQueryResult)).contains(updated.getId()); }); }
@Test public void queryByName() throws Exception { with2products("queryByName", (p1, p2) ->{ final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.name().lang(ENGLISH).is(en(p1.getMasterData().getStaged().getName()))) .withSort(m -> m.createdAt().sort().desc()) .withLimit(1L); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId()); }); }