Refactor helper functions, improve product filtering, and update seeders. Adjusted SMS sending logic for better readability, implemented multi-level category filtering in ProductRepository, and commented out old data seeding in ChannelTableSeeder and UserTableSeeder for a cleaner setup.
This commit is contained in:
@@ -4,10 +4,12 @@ namespace App\Repositories\Ecommerce\Product;
|
||||
|
||||
use App\Helpers\Ecommerce\Product\Filter\ProductFilterer;
|
||||
use App\Helpers\Ecommerce\Product\Sort\ProductSorter;
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductRepository
|
||||
{
|
||||
@@ -134,6 +136,35 @@ class ProductRepository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function applyMultiLevelFilter(Category $category): self
|
||||
{
|
||||
$categoryId = $category->id;
|
||||
|
||||
$categoryIds = collect(DB::select('
|
||||
WITH RECURSIVE category_tree AS (
|
||||
SELECT id FROM categories WHERE id = ?
|
||||
UNION
|
||||
SELECT c.id
|
||||
FROM categories c
|
||||
JOIN category_tree ct ON c.parent_id = ct.id
|
||||
)
|
||||
SELECT id FROM category_tree
|
||||
', [$categoryId]))->pluck('id');
|
||||
|
||||
$products = DB::table('products')
|
||||
->join('product_has_relations', 'products.id', '=', 'product_has_relations.product_id')
|
||||
->whereIn('product_has_relations.productable_id', $categoryIds)
|
||||
->where('product_has_relations.productable_type', '=', 'category')
|
||||
->select('products.id')
|
||||
->distinct()
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
$this->queryBuilder->whereIntegerInRaw('products.id', $products);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply sorting
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user