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:
Mekan1206
2025-12-19 21:50:17 +05:00
parent 19cc47942b
commit ba9402afb0
7 changed files with 59 additions and 26 deletions

View File

@@ -83,8 +83,8 @@ if (! function_exists('sendSMS')) {
return true; return true;
}) })
->post('http://216.250.14.144:3000/api/data', [ ->post('http://216.250.14.144:3000/api/data', [
'phone' => '+993'.$phone, 'phone' => '+993'.$phone,
'code' => $message, 'code' => $message,
]); ]);
return $response->body(); return $response->body();
@@ -396,7 +396,7 @@ function createHalkbankOrder($price = 123): array
return [ return [
'status' => 'failed', 'status' => 'failed',
'url' => '', 'url' => '',
'orderId' => '' 'orderId' => '',
]; ];
} }
@@ -407,7 +407,6 @@ function createHalkbankOrder($price = 123): array
]; ];
} }
/** /**
* Original quality :D * Original quality :D
*/ */

View File

@@ -62,7 +62,8 @@ class CategoryController extends Controller
return response()->rest_paginate( return response()->rest_paginate(
ProductResource::collection( ProductResource::collection(
ProductRepository::make($request) ProductRepository::make($request)
->queryAsFromResource($category) // ->queryAsFromResource($category)
->applyMultiLevelFilter($category)
->applyBasicQueries() ->applyBasicQueries()
->applyFilters() ->applyFilters()
->applySorting() ->applySorting()

View File

@@ -99,13 +99,13 @@ class SendOrderCreatedNotification implements ShouldQueue
Log::channel('order_sms_notification_sent_activity') Log::channel('order_sms_notification_sent_activity')
->info(sprintf('SMS_SENT_FOR_ORDER[id, phone]: %s, %s', $order->id, orderAdminNumber())); ->info(sprintf('SMS_SENT_FOR_ORDER[id, phone]: %s, %s', $order->id, orderAdminNumber()));
User::where('phone_number', orderAdminNumber())->first()->notify( User::where('phone_number', orderAdminNumber())->first()->notify(
NovaNotification::make() NovaNotification::make()
->message('Täze sargyt.') ->message('Täze sargyt.')
->action('Gör', sprintf('/turkmenpostadmin/resources/orders/%s', $order->id)) ->action('Gör', sprintf('/turkmenpostadmin/resources/orders/%s', $order->id))
->icon('download') ->icon('download')
->type('info') ->type('info')
); );
} }
} }

View File

@@ -4,10 +4,12 @@ namespace App\Repositories\Ecommerce\Product;
use App\Helpers\Ecommerce\Product\Filter\ProductFilterer; use App\Helpers\Ecommerce\Product\Filter\ProductFilterer;
use App\Helpers\Ecommerce\Product\Sort\ProductSorter; use App\Helpers\Ecommerce\Product\Sort\ProductSorter;
use App\Models\Ecommerce\Product\Category\Category;
use App\Models\Ecommerce\Product\Product\Product; use App\Models\Ecommerce\Product\Product\Product;
use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ProductRepository class ProductRepository
{ {
@@ -134,6 +136,35 @@ class ProductRepository
return $this; 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 * Apply sorting
*/ */

View File

@@ -14,7 +14,8 @@ class ChannelTableSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
$this->seedOldData(); // $this->seedOldData();
$this->seedStarterKit();
} }
/** /**

View File

@@ -17,27 +17,27 @@ class DatabaseSeeder extends Seeder
$this->call([ $this->call([
SettingsSeeder::class, SettingsSeeder::class,
RolesTableSeeder::class, RolesTableSeeder::class,
BannerTableSeeder::class, // BannerTableSeeder::class,
CarouselTableSeeder::class, // CarouselTableSeeder::class,
UserTableSeeder::class, UserTableSeeder::class,
ChannelTableSeeder::class, ChannelTableSeeder::class,
PaymentTypeTableSeeder::class, PaymentTypeTableSeeder::class,
ProvinceTableSeeder::class, ProvinceTableSeeder::class,
BrandTableSeeder::class, BrandTableSeeder::class,
ProductTableSeeder::class, // ProductTableSeeder::class,
PostBranchTableSeeder::class, PostBranchTableSeeder::class,
InventoriesTableSeeder::class, // InventoriesTableSeeder::class,
CategoryTableSeeder::class, CategoryTableSeeder::class,
CollectionTableSeeder::class, CollectionTableSeeder::class,
AttributeTableSeeder::class, // AttributeTableSeeder::class,
ContactUsTableSeeder::class, // ContactUsTableSeeder::class,
LegalPageTableSeeder::class, LegalPageTableSeeder::class,
ReviewTableSeeder::class, // ReviewTableSeeder::class,
NewsletterTableSeeder::class, // NewsletterTableSeeder::class,
CartItemTableSeeder::class, // CartItemTableSeeder::class,
FavouriteTableSeeder::class, // FavouriteTableSeeder::class,
MediaTableSeeder::class, // MediaTableSeeder::class,
ProductHasRelationsTable::class, // ProductHasRelationsTable::class,
]); ]);
} }
} }

View File

@@ -15,7 +15,8 @@ class UserTableSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
$this->seedOldData(); // $this->seedOldData();
$this->seedStarterKit();
} }
/** /**