Feature: Products Restructuring to follow a strict rule

This commit is contained in:
2026-08-27 01:05:04 +03:00
parent b3b5ca740d
commit ef356a6397
11 changed files with 45 additions and 42 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ use Lunar\Models\Language;
/**
* Cached read layer over Lunar's `languages` table — the single source both
* Modules\Core\Localization\LocaleMiddleware (request-time locale resolution) and
* any other locale-aware code (e.g. Modules\Core\Catalog\ProductService) read
* any other locale-aware code (e.g. Modules\Core\Product\Services\ProductService) read
* from, so the language list is fetched once per cache lifetime rather than once
* per caller. Cached forever, invalidated via forget() by
* Modules\Core\Localization\Listeners\FlushLanguageCache on
@@ -41,7 +41,7 @@ class LanguageCache
/**
* Every configured store locale code (e.g. ['el', 'en']) - for code that needs
* to enumerate all locales a TranslatedText attribute was indexed under (see
* Modules\Core\Catalog\ProductService::withLocalizedFields()), rather than
* Modules\Core\Product\Services\ProductService::withLocalizedFields()), rather than
* hardcoding locale codes.
*
* @return array<int, string>
@@ -1,13 +1,13 @@
<?php
namespace Modules\Core\Catalog;
namespace Modules\Core\Product\DTOs;
/**
* Filter input for ProductService::list(). All fields are optional — omitted
* filters are simply not added to the Meilisearch query. Values are matched
* against Modules\Core\Search\ProductIndexer's document fields, so filtering
* only works on stores where that indexer is registered and the index has
* been re-synced (see docs/product-listing.md).
* against Modules\Core\Product\Services\ProductIndexer's document fields, so
* filtering only works on stores where that indexer is registered and the index
* has been re-synced (see docs/product-listing.md).
*/
class ProductFilters
{
@@ -1,12 +1,13 @@
<?php
namespace Modules\Core\Catalog;
namespace Modules\Core\Product\Enums;
/**
* Sort options for ProductService::list(), each mapped to a Meilisearch `sort`
* clause against a field indexed as sortable by Modules\Core\Search\ProductIndexer
* (see its getSortableFields()). Adding a case here requires the matching field
* to also be sortable in the index, re-synced via `php artisan lunar:meilisearch:setup`.
* clause against a field indexed as sortable by Modules\Core\Product\Services\
* ProductIndexer (see its getSortableFields()). Adding a case here requires the
* matching field to also be sortable in the index, re-synced via
* `php artisan lunar:meilisearch:setup`.
*/
enum ProductSort: string
{
@@ -1,6 +1,6 @@
<?php
namespace Modules\Core\Search;
namespace Modules\Core\Product\Services;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
@@ -13,9 +13,9 @@ use Modules\Core\Review\Models\ProductReview;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
/**
* Extends Lunar's own indexer so Modules\Core\Catalog\ProductService can serve both
* listing/filtering AND single-product lookups from Meilisearch alone — one data
* source, no separate database read path for a product detail page. Adds:
* Extends Lunar's own indexer so Modules\Core\Product\Services\ProductService can
* serve both listing/filtering AND single-product lookups from Meilisearch alone —
* one data source, no separate database read path for a product detail page. Adds:
* - collections (ids, filterable) and collection_names (display)
* - slugs (every locale's Url::slug for the product, filterable) — lets
* ProductService::getBySlug() resolve a product from the index directly, with
@@ -1,6 +1,6 @@
<?php
namespace Modules\Core\Search;
namespace Modules\Core\Product\Services;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\App;
@@ -1,6 +1,6 @@
<?php
namespace Modules\Core\Catalog;
namespace Modules\Core\Product\Services;
use Illuminate\Contracts\Pagination\LengthAwarePaginator as LengthAwarePaginatorContract;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -10,15 +10,17 @@ use Lunar\Base\AttributeManifest;
use Lunar\FieldTypes\TranslatedText;
use Lunar\Models\Product;
use Modules\Core\Localization\Services\LanguageCache;
use Modules\Core\Product\DTOs\ProductFilters;
use Modules\Core\Product\Enums\ProductSort;
/**
* Storefront product listing/filtering AND single-product lookup, all reading directly
* from the Meilisearch index (Modules\Core\Search\ProductIndexer) - one data source, no
* ->get() model hydration anywhere in this service. Callers get plain arrays of the
* indexed document, not Eloquent models.
* from the Meilisearch index (Modules\Core\Product\Services\ProductIndexer) - one data
* source, no ->get() model hydration anywhere in this service. Callers get plain arrays
* of the indexed document, not Eloquent models.
*
* Full-text query search lives separately in Modules\Core\Search\ProductSearchService;
* this service is for browsing/filtering without a search term.
* Full-text query search lives separately in Modules\Core\Product\Services\
* ProductSearchService; this service is for browsing/filtering without a search term.
*/
class ProductService
{
@@ -60,8 +62,8 @@ class ProductService
/**
* Look up a single product by its URL slug (any locale - slugs are indexed across
* all languages, see Modules\Core\Search\ProductIndexer). Returns the full indexed
* product document, or null if no product has that slug.
* all languages, see Modules\Core\Product\Services\ProductIndexer). Returns the full
* indexed product document, or null if no product has that slug.
*/
public function getBySlug(string $slug): ?array
{
+2 -2
View File
@@ -9,8 +9,8 @@ use Modules\Core\Review\Models\ProductReview;
* Keeps a product's Meilisearch document in sync with its reviews. A review is
* created/edited independently of its product (customer submission, staff reply),
* so the product's own save/update events never fire for it — without this listener,
* Modules\Core\Search\ProductIndexer's review data would only refresh on the next
* full product reindex.
* Modules\Core\Product\Services\ProductIndexer's review data would only refresh on
* the next full product reindex.
*/
class ReviewServiceProvider extends ServiceProvider
{
+2 -2
View File
@@ -38,8 +38,8 @@ class ProductReview extends Model implements HasMedia
* Unlike Product/ProductVariant, this model sits outside Lunar's own
* MediaDefinitionsInterface (Lunar\Base\StandardMediaDefinitions), which is
* what registers the 'small' conversion those models get automatically. Without
* this, Modules\Core\Search\ProductIndexer::mapMedia() — shared across product,
* variant, and review media — throws Spatie\MediaLibrary\MediaCollections\
* this, Modules\Core\Product\Services\ProductIndexer::mapMedia() — shared across
* product, variant, and review media — throws Spatie\MediaLibrary\MediaCollections\
* Exceptions\InvalidConversion the first time a review has an image, since
* $media->getUrl('small') has no matching conversion to resolve.
*/