How can I add custom attributes to the listing model?
You can extend the \Aero\Search\Elastic\Pipelines\ListingAttributes pipeline to add custom attributes to the listing model.
For example you can modify the listing's name to include the attributes when the listing is split by them.
\Aero\Search\Elastic\Pipelines\ListingAttributes::extend(function (array $attributes, \Closure $next) {
$splitAttributeGroups = collect($attributes['attribute_groups'] ?? [])
->filter(function ($attributeGroup) {
return $attributeGroup['split'] ?? false;
});
if ($splitAttributeGroups->isEmpty()) {
return $next($attributes);
}
$attributeNames = $splitAttributeGroups->flatMap(function (array $attributeGroup) {
return collect($attributeGroup['attributes'] ?? [])->pluck('name');
});
$attributes['name'] = "{$attributeNames->implode(' ')} {$attributes['name']}";
return $next($attributes);
});
This means if you have a product split by a Colour attribute group, each listing would now be named {colour} {name}, e.g. Red Puffer Jack.