CustomAttributesAdapter<T> class
abstract
Universal adapter for working with custom product attributes.
This abstract class provides a flexible framework for handling custom product attributes in Magento. It allows each application to define its own attribute schema and provides methods for conversion, validation, and filtering.
Features
- Type Safety: Generic type parameter ensures type safety for custom models
- Bidirectional Conversion: Convert between Magento attributes and typed models
- Validation: Built-in validation system for custom attributes
- Search Integration: Create search filters from custom attribute values
- Extensibility: Support for custom attribute metadata and transformations
- Compatibility: Version tracking for adapter compatibility
Usage
class MyCustomAdapter extends CustomAttributesAdapter<MyProductModel> {
@override
MyProductModel fromCustomAttributes(List<CustomAttribute> attributes) {
// Convert Magento attributes to your custom model
}
@override
List<CustomAttribute> toCustomAttributes(MyProductModel model) {
// Convert your model back to Magento attributes
}
}
Constructors
Properties
- adapterId → String
-
Get unique identifier for this adapter.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedAttributeCodes
→ List<
String> -
Returns list of attribute codes that this adapter handles.
no setter
- version → String
-
Get adapter version for compatibility checking
no setter
Methods
-
buildSearchFilters(
T model) → Map< String, dynamic> - Create search filters for custom attributes.
-
canHandle(
List< CustomAttribute> attributes) → bool - Check if this adapter can handle the given attributes
-
fromCustomAttributes(
List< CustomAttribute> attributes) → T - Convert list of Magento CustomAttribute to typed model.
-
getAttributeDisplayName(
String attributeCode) → String - Get attribute display name
-
getAttributeMetadata(
String attributeCode) → Map< String, dynamic> - Get attribute metadata (optional)
-
getAttributeValue<
U> (List< CustomAttribute> attributes, String code) → U? - Get attribute value by code with type casting.
-
getDefaultValue(
String attributeCode) → dynamic - Get default value for an attribute (optional)
-
isRequired(
String attributeCode) → bool - Check if attribute is required
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toCustomAttributes(
T model) → List< CustomAttribute> - Convert typed model back to list of Magento CustomAttribute.
-
toString(
) → String -
A string representation of this object.
inherited
-
transformAttributeValue(
String attributeCode, String rawValue) → dynamic - Transform raw attribute value based on type
-
validate(
T model) → ValidationResult - Validate the custom model instance.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited