Files
core/src/Catalog/Recommendations/RandomRule.php
T

28 lines
905 B
PHP
Raw Normal View History

2026-09-01 12:06:29 +03:00
<?php
namespace Modules\Core\Catalog\Recommendations;
use Illuminate\Support\Collection;
use Lunar\Models\Product;
use Modules\Core\Catalog\Contracts\RecommendationRule;
/**
* The universal fallback — always returns something as long as the store
* has more than one product, since it has no eligibility condition of its
* own to come up empty on. Meant to be placed last in
* config('catalog.recommendation_rules'), not first: every store using
* the default chain gets a real fallback, but one that only kicks in once
* more specific rules (same category, same tag, ...) have had a chance.
*/
class RandomRule implements RecommendationRule
{
public function recommend(Product $product, int $limit, array $exclude): Collection
{
return Product::query()
->whereKeyNot($exclude)
->inRandomOrder()
->limit($limit)
->get();
}
}