@Override protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) { return enumValue.getLabel(); }
@Override protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) { return enumValue.getLabel(); }
@Override protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) { return enumValue.getLabel(); }
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 facetedSearchOnEnumLabelSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnumSet(ATTR_NAME_ENUM_SET).label().is(ENUM_THREE.getLabel()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(ENUM_TWO.getLabel(), 2L), TermStats.of(ENUM_THREE.getLabel(), 1L))); }
@Test public void readAttributeGetValueAs() throws Exception { final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant(); final String attributeValue = masterVariant.findAttribute(SIZE_ATTR_NAME) .map((Attribute a) -> { final EnumValue enumValue = a.getValueAsEnumValue(); return enumValue.getLabel(); }) .orElse("not found"); assertThat(attributeValue).isEqualTo("S"); }
@Test public void facetedSearchOnEnumLabelAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).label().is(ENUM_TWO.getLabel()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(ENUM_TWO.getLabel(), 1L), TermStats.of(ENUM_THREE.getLabel(), 1L))); }
final Optional<String> extractedResult = AttributeExtraction.<String>of(productType, attribute) .ifIs(AttributeAccess.ofLocalizedEnumValue(), v -> v.getLabel().find(ENGLISH).orElse("")) .ifIs(AttributeAccess.ofEnumValue(), v -> v.getLabel()) .ifIs(AttributeAccess.ofLocalizedEnumValueSet(), v -> v.stream()
@Test public void onEnumLabelSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofEnumSet(ATTR_NAME_ENUM_SET).label().is(ENUM_THREE.getLabel()), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onEnumLabelAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).label().is(ENUM_TWO.getLabel()), ids -> assertThat(ids).containsOnly(product1.getId())); }