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:
@@ -396,7 +396,7 @@ function createHalkbankOrder($price = 123): array
|
||||
return [
|
||||
'status' => 'failed',
|
||||
'url' => '',
|
||||
'orderId' => ''
|
||||
'orderId' => '',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -407,7 +407,6 @@ function createHalkbankOrder($price = 123): array
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Original quality :D
|
||||
*/
|
||||
|
||||
@@ -62,7 +62,8 @@ class CategoryController extends Controller
|
||||
return response()->rest_paginate(
|
||||
ProductResource::collection(
|
||||
ProductRepository::make($request)
|
||||
->queryAsFromResource($category)
|
||||
// ->queryAsFromResource($category)
|
||||
->applyMultiLevelFilter($category)
|
||||
->applyBasicQueries()
|
||||
->applyFilters()
|
||||
->applySorting()
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,8 @@ class ChannelTableSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
// $this->seedOldData();
|
||||
$this->seedStarterKit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,27 +17,27 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call([
|
||||
SettingsSeeder::class,
|
||||
RolesTableSeeder::class,
|
||||
BannerTableSeeder::class,
|
||||
CarouselTableSeeder::class,
|
||||
// BannerTableSeeder::class,
|
||||
// CarouselTableSeeder::class,
|
||||
UserTableSeeder::class,
|
||||
ChannelTableSeeder::class,
|
||||
PaymentTypeTableSeeder::class,
|
||||
ProvinceTableSeeder::class,
|
||||
BrandTableSeeder::class,
|
||||
ProductTableSeeder::class,
|
||||
// ProductTableSeeder::class,
|
||||
PostBranchTableSeeder::class,
|
||||
InventoriesTableSeeder::class,
|
||||
// InventoriesTableSeeder::class,
|
||||
CategoryTableSeeder::class,
|
||||
CollectionTableSeeder::class,
|
||||
AttributeTableSeeder::class,
|
||||
ContactUsTableSeeder::class,
|
||||
// AttributeTableSeeder::class,
|
||||
// ContactUsTableSeeder::class,
|
||||
LegalPageTableSeeder::class,
|
||||
ReviewTableSeeder::class,
|
||||
NewsletterTableSeeder::class,
|
||||
CartItemTableSeeder::class,
|
||||
FavouriteTableSeeder::class,
|
||||
MediaTableSeeder::class,
|
||||
ProductHasRelationsTable::class,
|
||||
// ReviewTableSeeder::class,
|
||||
// NewsletterTableSeeder::class,
|
||||
// CartItemTableSeeder::class,
|
||||
// FavouriteTableSeeder::class,
|
||||
// MediaTableSeeder::class,
|
||||
// ProductHasRelationsTable::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ class UserTableSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedOldData();
|
||||
// $this->seedOldData();
|
||||
$this->seedStarterKit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user