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;
})
->post('http://216.250.14.144:3000/api/data', [
'phone' => '+993'.$phone,
'code' => $message,
'phone' => '+993'.$phone,
'code' => $message,
]);
return $response->body();
@@ -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
*/

View File

@@ -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()

View File

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