@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
public static String attributeValue(final Attribute attribute, final List<Locale> locales, final MetaProductType metaProductType) { final AttributeExtraction<String> attributeExtraction = AttributeExtraction.of(metaProductType, attribute); return attributeExtraction .ifIs(AttributeAccess.ofLocalizedString(), v -> v.find(locales).orElse("")) .ifIs(AttributeAccess.ofLocalizedEnumValue(), v -> v.getLabel().find(locales).orElse("")) .ifIs(AttributeAccess.ofEnumValue(), v -> v.getLabel()) .ifIs(AttributeAccess.ofString(), v -> v) .findValue() .orElse(""); }
@Test public void shouldSerializeLocalizedEnumValueCorrectly() { final LocalizedString localizedString = LocalizedString.of(Locale.GERMAN, "german-text"); final LocalizedEnumValue localizedEnumValue = LocalizedEnumValue.of("key", localizedString); final AttributeDraft attributeDraft = AttributeDraft.of(AttributeAccess.ofLocalizedEnumValue().ofName("name"), localizedEnumValue); final JsonNode jsonValue = attributeDraft.getValue(); assertThat(jsonValue.get("key").asText()).isEqualTo(localizedEnumValue.getKey()); final JsonNode jsonLabel = jsonValue.get("label"); assertThat(jsonLabel.get("de").asText()).isEqualTo(localizedEnumValue.getLabel().get(Locale.GERMAN)); } }
@Test public void facetedSearchOnLocEnumLabelSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).label().locale(GERMAN).is(LOC_ENUM_THREE.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 2L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void facetedSearchOnLocEnumLabelAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).is(LOC_ENUM_TWO.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 1L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void onLocEnumLabelSetAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).label().locale(GERMAN).allTerms(), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 2L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void onLocEnumLabelAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).allTerms(), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 1L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void onLocEnumLabelAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).is(LOC_ENUM_TWO.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onLocEnumLabelSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).label().locale(GERMAN).is(LOC_ENUM_THREE.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId())); }