cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create range feature with classification api

former_member633554
Active Participant
0 Likes
444

Hi,

For this range classification feature type, this code always creates the feature value at position 1. Is there a way to specify valueposition 0?

I'm using the classification api. https://help.hybris.com/6.7.0/hcd/8b7a777486691014823afa6e0ed7bb61.html

  FeatureList featureList = classificationService.getFeatures(product1);
 final Feature feature = featureList.getFeatureByCode("Classification/1.0/Measures_Volts.voltage_range");
 println feature
 ClassificationAttributeUnitModel classificationAttributeUnit = classificationSystemService.getAttributeUnitForCode(version, "pct");
 feature.addValue(new FeatureValue(11,'',classificationAttributeUnit));    
 classificationService.setFeatures(product1, featureList);
 modelService.saveAll(product1)

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member633554
Active Participant
0 Likes

Looks like i'll have to use this massively more verbose code unfortunately. But it works!

 final ClassificationSystemModel classSystemMean = modelService.create(ClassificationSystemModel.class);
         classSystemMean.setId("Classification/1.0");
 
         classSystemVersionMean = modelService.create(ClassificationSystemVersionModel.class);
         classSystemVersionMean.setCatalog(classSystemMean);
         classSystemVersionMean.setVersion("Classification/1.0");
 
         classClassMean = modelService.create(ClassificationClassModel.class);
         classClassMean.setCatalogVersion(classSystemVersionMean);
         classClassMean.setCode("Measures_Volts.class");
 
         classPropertyMean = new ClassificationAttributeModel();
         classPropertyMean.setCode("thermometer_resolution");
         classPropertyMean.setSystemVersion(classSystemVersionMean);
 
         classPropertyAssignmentMean = modelService.create(ClassAttributeAssignmentModel.class);
         classPropertyAssignmentMean.setClassificationAttribute(classPropertyMean);
         classPropertyAssignmentMean.setClassificationClass(classClassMean);
         classPropertyAssignmentMean.setSystemVersion(classSystemVersionMean);
 
 
 
 
 final   ProductFeatureModel productFeature = modelService.create(ProductFeatureModel.class);
         productFeature.setProduct(product1);
         productFeature.setValue(12);
         productFeature.setClassificationAttributeAssignment(classPropertyAssignmentMean);
         productFeature.setQualifier('Classification/1.0/Measures_Volts.voltage_range');
         productFeature.setValuePosition(Integer.valueOf(0));
         modelService.save(productFeature);
 modelService.saveAll(product1)
former_member633554
Active Participant
0 Likes

Thanks but it seems to have no affect on the valueposition column in the table. Still always goes to valueposition 1 instead of 0.

 feature.addValue(0, new FeatureValue(11,'',classificationAttributeUnit)); 
geffchang
Active Contributor
0 Likes

Specify the position using the other Feature.addValue method (which contains an index parameter): https://help.hybris.com/6.7.0/api/commerce-suite/de/hybris/platform/classification/features/Feature....