Skip to content

Commit

Permalink
fix order search by email
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Jul 17, 2024
1 parent 9729a83 commit 63bbfb8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Docs/V1/Admin/Controllers/Sales/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public function list()

/**
* @OA\Get(
* path="/api/v1/admin/sales/orders/search",
* path="/api/v1/admin/sales/orders/find-by-email",
* operationId="SearchSalesOrders",
* tags={"Orders"},
* summary="Search admin order list",
* summary="Search admin order list by email",
* description="Returns order list, if you want to retrieve all orders at once pass pagination=0 otherwise ignore this parameter",
* security={ {"sanctum_admin": {} }},
*
Expand Down
17 changes: 16 additions & 1 deletion src/Http/Controllers/Api/V1/Admin/Sales/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use NexaMerchant\Apis\Http\Resources\Api\V1\Admin\Sales\OrderResource;
use Webkul\Sales\Repositories\OrderCommentRepository;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Models\Order;

class OrderController extends SalesController
{
Expand Down Expand Up @@ -36,8 +37,22 @@ public function findByEmail(Request $request)
$validatedData = $request->validate([
'email' => 'required',
]);
$results = $this->getRepositoryInstance()->findByEmail($request->get('email'));

$order = $request->get('order') ?? 'desc';
$sort = $request->get('sort') ?? 'id';
$page = $request->get('page') ?? 1;
$limit = $request->get('limit') ?? 10;
$query = Order::query();

$query->where('customer_email', $request->get('email'));
$query->orderBy($sort, $order);
$query->paginate($limit, ['*'], 'page', $page);

$results = $query->get();


// $results = $this->getRepositoryInstance()->findWhere(["customer_email" => $request->get('email')])->orderBy($sort, $order)->paginate($limit, ['*'], 'page', $page);

return $this->resource()::collection($results);
}

Expand Down
1 change: 1 addition & 0 deletions src/Http/Middleware/AssignRequestId.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function handle(Request $request, Closure $next): Response
$response = $next($request);

$response->headers->set('Request-Id', $requestId);


return $response;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Routes/V1/Admin/sales-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* Order routes.
*/
Route::controller(OrderController::class)->prefix('orders')->group(function () {
Route::get('', 'allResources');

Route::get('find-by-email', 'findByEmail');

Route::get('', 'allResources');

Route::get('{id}', 'getResource');

Route::post('{id}/cancel', 'cancel');
Expand Down

0 comments on commit 63bbfb8

Please sign in to comment.