final Reference<ProductType> productType = productProjection.getProductType(); final List<Map.Entry<String, String>> attributes = formatter.createAttributeEntryList(variant, productType, attrNamesToShow); final int valueColumnWidth = getMaxTranslatedValueLength(attributes);
@Test public void allowsExpansion() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().withLimit(1L); testResult(search, result -> { final List<ProductProjection> results = result.getResults(); assertThat(results).isNotEmpty(); assertThat(results.get(0).getProductType().getObj()).isNull(); }); testResult(search.withExpansionPaths(product -> { return product.productType(); }), result -> { final List<ProductProjection> results = result.getResults(); assertThat(results).isNotEmpty(); assertThat(results.get(0).getProductType().getObj()).isEqualTo(productType); }); }
final ProductType productType = productProjection.getProductType().getObj(); final ProductVariant masterVariant = productProjection.getMasterVariant(); final List<Attribute> attributes = masterVariant.getAttributes();
@Test public void queryByProductType() throws Exception { with2products("queryByProductType", (p1, p2) ->{ final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .byProductType(p1.getProductType()) .withExpansionPaths(m -> m.productType()); final PagedQueryResult<ProductProjection> queryResult = client().executeBlocking(query); assertThat(queryResult.head().get().getProductType()).is(expanded()); assertThat(ids(queryResult)).containsOnly(p1.getId()); }); }
@Test public void showProductAttributeTableWithDefaultFormatter() throws Exception { final List<String> attrNamesToShow = asList(COLOR_ATTR_NAME, SIZE_ATTR_NAME, MATCHING_PRODUCTS_ATTR_NAME, LAUNDRY_SYMBOLS_ATTR_NAME, RRP_ATTR_NAME, AVAILABLE_SINCE_ATTR_NAME); final Product product = createProduct(); final ProductProjectionQuery query = ProductProjectionQuery.ofStaged() .withPredicates(m -> m.id().is(product.getId())) .plusExpansionPaths(m -> m.masterVariant().attributes().valueSet()) .plusExpansionPaths(m -> m.productType()); final ProductProjection productProjection = client().executeBlocking(query).head().get(); final List<ProductType> productTypes = Collections.singletonList(productProjection.getProductType().getObj()); final List<Locale> locales = Collections.singletonList(ENGLISH); final DefaultProductAttributeFormatter formatter = DefaultProductAttributeFormatterDemo.createFormatter(productTypes, locales); DefaultProductAttributeFormatterDemo.example(attrNamesToShow, productProjection, formatter); }