Feature: Adding back ChannelIds on Product Indexer
This commit is contained in:
@@ -27,6 +27,9 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
* - reviews: public-safe fields only (see mapReview() — reviewer_email is deliberately
|
||||
* excluded, it's PII with no storefront use), including staff replies, plus an
|
||||
* average rating
|
||||
* - channel_ids (filterable) — Lunar's base indexer only indexes "status" as
|
||||
* filterable, not channel assignment, so search results can't otherwise be
|
||||
* scoped to products actually assigned+enabled on the current sales channel
|
||||
*
|
||||
* A review is created/edited independently of its product (Modules\Core\Providers\
|
||||
* ReviewServiceProvider re-indexes the product on review create/update/delete), so
|
||||
@@ -49,6 +52,7 @@ class ProductIndexer extends BaseProductIndexer
|
||||
'collections',
|
||||
'price',
|
||||
'slugs',
|
||||
'channel_ids',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -83,6 +87,10 @@ class ProductIndexer extends BaseProductIndexer
|
||||
$data['reviews'] = $reviews->map(fn (ProductReview $review) => $this->mapReview($review))->all();
|
||||
$data['review_count'] = $reviews->count();
|
||||
$data['average_rating'] = $reviews->isEmpty() ? null : round($reviews->avg('rating'), 1);
|
||||
$data['channel_ids'] = $model->channels()
|
||||
->wherePivot('enabled', true)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user