PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / api / Resource / FrontendResource / OrderResource.php

OrderResource.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at api/Resource/FrontendResource/OrderResource.php

123 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Api\Resource\FrontendResource;
4
5 use FluentCart\Api\Orders;
6 use FluentCart\Api\Resource\BaseResourceApi;
7 use FluentCart\App\App;
8 use FluentCart\App\Models\Order;
9 use FluentCart\Framework\Database\Orm\Builder;
10 use FluentCart\Framework\Support\Arr;
11
12 class OrderResource extends BaseResourceApi
13 {
14 public static function getQuery(): Builder
15 {
16 return Order::query();
17 }
18
19 /**
20 * Retrieve orders with additional data based on specified parameters.
21 *
22 * @param array $params Optional. Additional parameters for order retrieval.
23 * $params = [
24 * 'search' => (string) Optional. Search Order.
25 * [
26 * "column name(e.g., customer_id)" => [
27 * column => "column name(e.g., customer_id)",
28 * value => "value" ]
29 * ],
30 * 'order_by' => (string) Optional. Column to order by,
31 * 'order_type' => (string) Optional. Order type for sorting (ASC or DESC),
32 * 'per_page' => (int) Optional. Number of items for per page,
33 * 'page' => (int) Optional. Page number for pagination
34 * ]
35 *
36 */
37 public static function get(array $params = [])
38 {
39 $searchConditions = Arr::get($params, 'search.search_conditions', []);
40 $with = Arr::get($params, 'with', []);
41 $requestParams = Arr::get($params, 'params', []);
42
43 $orderBy = sanitize_sql_orderby(Arr::get($requestParams, 'order_by', 'id'));
44 $orderType = sanitize_sql_orderby(Arr::get($requestParams, 'order_type', 'DESC'));
45 $perPage = Arr::get($requestParams, 'per_page', 10);
46 $page = Arr::get($requestParams, 'page', 1);
47 $searchId = Arr::get($params, 'search.id');
48
49 return static::getQuery()
50 ->with($with)
51 ->whereHas('customer', function ($query) use ($searchId) {
52 return $query->where('id', $searchId);
53 })
54 ->search($searchConditions)
55 ->orderBy(
56 sanitize_sql_orderby($orderBy),
57 sanitize_sql_orderby($orderType))
58 ->paginate($perPage, ['*'], 'page', $page);
59 }
60
61 /**
62 * Find order based on the given id and parameters.
63 *
64 * @param int $id Required. The id of the order.
65 * @param array $params Optional. Array containing the necessary parameters.
66 *
67 */
68 public static function find($id, $params = [])
69 {
70 $with = Arr::get($params, 'with', []);
71 return static::getQuery()
72 ->with($with)
73 ->with([
74 'customer' => function ($query) {
75 $query->with(['billing_address' => function ($query) {
76 $query->where('is_primary', '1');
77 }]);
78 $query->with(['shipping_address' => function ($query) {
79 $query->where('is_primary', '1');
80 }]);
81 }
82 ])
83 ->where('uuid', $id)
84 ->first();
85 }
86
87 /**
88 * Create order address with the given data.
89 *
90 * @param array $data Required. Array containing the necessary parameters
91 * @param array $params Required. Additional parameters for creating an order.
92 *
93 */
94 public static function create($data, $params = [])
95 {
96 //
97 }
98
99 /**
100 * Update order with the given data.
101 *
102 * @param array $data Required. Array containing the necessary parameters
103 * @param int $id Required. The id of the order to be updated.
104 *
105 */
106 public static function update($data, $id, $params = [])
107 {
108 //
109 }
110
111 /**
112 * Delete an order based on the given id and parameters.
113 *
114 * @param int $id Required. The id of the order.
115 * @param array $params Optional. Additional parameters for order deletion.
116 *
117 */
118 public static function delete($id, $params = [])
119 {
120 //
121 }
122 }
123