I want to assing new values to a feature of a (variant) product in hybris. The features (qualifiers) and their values are defined in a textfile. The feature is already part of this product classification but it is currently neither set at the variant nor at the base product. Hence both times Null is returned when I try to fetch it:
feature = getFeatureFromProduct(product, qualifier)
if (! feature) {
log.info "$qualifier does not exist for $product.code"
}
base = ((VariantProductModel) product).getBaseProduct()
log.info "Base: $base.code"
baseFeature = getFeatureFromProduct(base, attribute.qualifier)
if (! baseFeature) {
log.info "$qualifier does not exist for $product.code"
}
That's the method to get the feature:
static ProductFeatureModel getFeatureFromProduct(ProductModel product, String qualifier){
return product.getFeatures()
.stream()
.filter {feature -> feature.getQualifier() == qualifier}
.findFirst()
.orElse(null)
}
So I have to do one or two things:
- Create an new
ProductFeatureModelbased on the qualifier and value. - Assing it to the product. (and maybe register somewhere that the feature may now be different for variants, so it's variant describing - I don't know the exact terminology for that)
How would I do that in groovy / using the hybris Java API?