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 / OrderAddressResource.php

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

136 lines 4.2 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\Resource\BaseResourceApi;
6 use FluentCart\App\Models\OrderAddress;
7 use FluentCart\Framework\Database\Orm\Builder;
8 use FluentCart\Framework\Support\Arr;
9
10 class OrderAddressResource extends BaseResourceApi
11 {
12 public static function getQuery(): Builder
13 {
14 return OrderAddress::query();
15 }
16
17 /**
18 * Get order addresses with specified parameters.
19 *
20 * @param array $params Array containing the necessary parameters.
21 *
22 */
23 public static function get(array $params = [])
24 {
25 //
26 }
27
28 /**
29 * Find order address based on the given ID and parameters.
30 *
31 * @param int $id Optional. The ID of the order address.
32 * @param array $params Optional. Array containing the necessary parameters.
33 *
34 */
35 public static function find($id = null, $params = [])
36 {
37 $address = null;
38
39 if ($id) {
40 $address = static::getQuery()->find($id);
41 }
42
43 $orderId = Arr::get($params, 'order_id');
44
45 if (empty($address) && !empty($orderId)) {
46 $type = Arr::get($params, 'type', 'billing');
47
48 $address = static::getQuery()
49 ->where('order_id', $orderId)
50 ->where('type', $type)
51 ->first();
52 }
53
54 return $address;
55 }
56
57 /**
58 * Create order address with the given data.
59 *
60 * @param array $data Required. Array containing the necessary parameters
61 * [
62 * 'order_id' => (int) Required. The id of the order.
63 * 'name' => (string) Required. The name of the address.
64 * 'address_1' => (string) Required. The primary address line.
65 * 'address_2' => (string) Optional. The secondary address line.
66 * 'city' => (string) Required. The city of the address.
67 * 'country' => (string) Required. The country of the address.
68 * 'postcode' => (string) Required. The postal code of the address.
69 * 'state' => (string) Required. The state of the address.
70 * 'type' => (string) Required. (e.g., 'billing', 'shipping').
71 * ]
72 * @param array $params Required. Additional parameters for creating an address.
73 *
74 */
75 public static function create($data, $params = [])
76 {
77 $isCreated = static::getQuery()->create($data);
78
79 if ($isCreated) {
80 return static::makeSuccessResponse(
81 $isCreated,
82 __('Order address created successfully!', 'fluent-cart')
83 );
84 }
85
86 return static::makeErrorResponse([
87 ['code' => 400, 'message' => __('Order address creation failed.', 'fluent-cart')]
88 ]);
89 }
90
91 /**
92 * Update order address with the given data.
93 *
94 * @param array $data Required. Array containing the necessary parameters
95 * @param int $id Required. The ID of the order address to be updated.
96 *
97 */
98 public static function update($data, $id, $params = [])
99 {
100 if (!$id) {
101 return static::makeErrorResponse([
102 ['code' => 403, 'message' => __('Please edit a valid address!', 'fluent-cart')]
103 ]);
104 }
105
106 $address = static::getQuery()->find($id);
107
108 if (!$address) {
109 return static::makeErrorResponse([
110 ['code' => 404, 'message' => __('Address not found, please reload the page and try again!', 'fluent-cart')]
111 ]);
112 }
113
114 $isUpdated = $address->update($data);
115
116 if ($isUpdated) {
117 static::makeSuccessResponse($isUpdated, __('Order address updated successfully!', 'fluent-cart'));
118 }
119
120 return static::makeErrorResponse([
121 ['code' => 400, 'message' => __('Order address update failed.', 'fluent-cart')]
122 ]);
123 }
124
125 /**
126 * Delete an address based on the given ID and parameters.
127 *
128 * @param int $id Required. The ID of the order address.
129 * @param array $params Optional. Additional parameters for address deletion.
130 *
131 */
132 public static function delete($id, $params = [])
133 {
134 //
135 }
136 }