MatchedProduct constructor
MatchedProduct(
- Product product,
- ProductPreferencesManager productPreferencesManager
Implementation
MatchedProduct(
this.product,
final ProductPreferencesManager productPreferencesManager,
) {
final List<AttributeGroup>? attributeGroups = product.attributeGroups;
if (attributeGroups == null) {
_status = null;
return;
}
_status = MatchedProductStatus.YES;
for (final AttributeGroup group in attributeGroups) {
if (group.attributes != null) {
for (final Attribute attribute in group.attributes!) {
final PreferenceImportance? preferenceImportance =
productPreferencesManager.getPreferenceImportanceFromImportanceId(
productPreferencesManager.getImportanceIdForAttributeId(
attribute.id!,
),
);
if (preferenceImportance != null) {
final String? importanceId = preferenceImportance.id;
final int factor = preferenceImportance.factor ?? 0;
final int? minimalMatch = preferenceImportance.minimalMatch;
if (importanceId == null || factor == 0) {
_debug += '${attribute.id} $importanceId\n';
} else {
if (attribute.status == Attribute.STATUS_UNKNOWN) {
if (_status == MatchedProductStatus.YES) {
_status = MatchedProductStatus.UNKNOWN;
}
} else {
_debug +=
'${attribute.id} $importanceId - match: ${attribute.match}\n';
_score += (attribute.match ?? 0) * factor;
if (minimalMatch != null &&
(attribute.match ?? 0) <= minimalMatch) {
_status = MatchedProductStatus.NO;
}
}
}
}
}
}
}
}