PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 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 All 48 releases
← All changes | app/Http/Controllers/FrontendControllers/CustomerController.php +60 -11 1.3.19 → 1.6.5 View file →
@@ -10,8 +10,9 @@
10 10 use FluentCart\App\Http\Controllers\Controller;
11 11 use FluentCart\App\Http\Requests\CustomerRequest;
12 12 use FluentCart\App\Http\Requests\FrontendRequests\CustomerAddressRequest;
13 13 use FluentCart\App\Models\CustomerAddresses;
14 +use FluentCart\App\Services\CustomerIdentity\EmailVerificationService;
14 15 use FluentCart\App\Services\Localization\LocalizationManager;
15 16 use FluentCart\App\Services\Renderer\AddressSelectRenderer;
16 17 use FluentCart\App\Services\Renderer\CheckoutFieldsSchema;
17 18 use FluentCart\Framework\Http\Request\Request;
@@ -60,9 +61,24 @@
60 61 return $this->sendError([
61 62 'message' => __('You are not authorized to view this customer', 'fluent-cart')
62 63 ]);
63 64 }
64 - return CustomerResource::find($customerId, ['with' => $request->get('with', [])]);
65 + // The customer never chooses its own eager loads. Forwarding the request's
66 + // `with` here let a logged-in customer walk relations off their own record
67 + // — `wpUser` for the WordPress user row, or `orders`/`subscriptions` for
68 + // gateway identifiers the account pages never show. The ownership check
69 + // above limits it to their own data, which is not the same as safe.
70 + //
71 + // These four are the customer's own addresses, which is what a profile
72 + // detail view is for. Anything wider belongs to the admin endpoint.
73 + return CustomerResource::find($customerId, [
74 + 'with' => [
75 + 'billing_address',
76 + 'shipping_address',
77 + 'primary_billing_address',
78 + 'primary_shipping_address',
79 + ],
80 + ]);
65 81 }
66 82
67 83 public function getAddress(Request $request, $customerId)
68 84 {
@@ -73,25 +89,38 @@
73 89 }
74 90
75 91 public function updateAddressSelect(Request $request, $customerAddressId)
76 92 {
77 - $address = CustomerAddressResource::find($customerAddressId, ['with' => $request->get('with', [])]);
93 + if (is_user_logged_in() && EmailVerificationService::isRequired(get_current_user_id())) {
94 + return $this->sendError([
95 + 'message' => __('Please verify your email before using saved addresses.', 'fluent-cart')
96 + ], 403);
97 + }
78 98
79 - if (!$address) {
99 + // The imported CustomerResource is the FrontendResource variant, which has
100 + // no getCurrentCustomer — calling it there hits BaseResourceApi::__callStatic
101 + // and 500s for every caller. The current-customer resolver lives on the
102 + // core resource, same as getDetails/createAddress above.
103 + $customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();
104 + if (!$customer) {
80 105 return $this->sendError([
81 106 'message' => __('Address not found', 'fluent-cart')
82 107 ]);
83 108 }
84 109
85 - // Verify address belongs to current customer before any cart mutation
86 - $customerId = Arr::get($address, 'address.customer_id');
87 - $customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();
88 - if (empty($customer) || $customer->id != $customerId) {
110 + $addressModel = CustomerAddresses::query()
111 + ->where('id', $customerAddressId)
112 + ->where('customer_id', $customer->id)
113 + ->first();
114 +
115 + if (!$addressModel) {
89 116 return $this->sendError([
90 - 'message' => __('You are not authorized to view this address', 'fluent-cart')
117 + 'message' => __('Address not found', 'fluent-cart')
91 118 ]);
92 119 }
93 120
121 + $address = ['address' => $addressModel];
122 +
94 123 //update address into cart
95 124 $addressId = Arr::get($address, 'address.id');
96 125 $country = Arr::get($address, 'address.country');
97 126 $state = Arr::get($address, 'address.state');
@@ -153,8 +182,14 @@
153 182
154 183
155 184 public function createAddress(Request $request) //CustomerAddressRequest
156 185 {
186 + if (is_user_logged_in() && EmailVerificationService::isRequired(get_current_user_id())) {
187 + return $this->sendError([
188 + 'message' => __('Please verify your email before using saved addresses.', 'fluent-cart')
189 + ], 403);
190 + }
191 +
157 192 $customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();
158 193
159 194 if (empty($customer)) {
160 195 return $this->sendError([
@@ -264,9 +299,9 @@
264 299 // Address creation validates against its own type's rules only — no shipping merge
265 300 $validations = array_filter(CheckoutFieldsSchema::getCheckoutFieldsRequirements($type, $fulfillmentType, false));
266 301
267 302 // Name fields are validated via basic_info, not address sections
268 - unset($validations['full_name'], $validations['first_name'], $validations['last_name'], $validations['company_name']);
303 + unset($validations['full_name'], $validations['first_name'], $validations['last_name']);
269 304
270 305 $address = [];
271 306 foreach ($validations as $key => $validation) {
272 307 $address[$key] = Arr::get($data, $type . '_' . $key, '');
@@ -374,8 +409,9 @@
374 409 }
375 410
376 411 public function updateAddress(CustomerAddressRequest $request)
377 412 {
413 +
378 414 $data = $request->getSafe($request->sanitize());
379 415 $data = self::formattedAddress($data);
380 416 $id = Arr::get($request->get('address'), 'id');
381 417
@@ -382,9 +418,9 @@
382 418 $address = CustomerAddresses::query()->findOrFail($id);
383 419
384 420 $customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();
385 421 if (empty($customer) || $customer->id != $address->customer_id) {
386 - $this->sendError([
422 + return $this->sendError([
387 423 'message' => __('You are not authorized to update this address', 'fluent-cart')
388 424 ]);
389 425 }
390 426
@@ -406,10 +442,11 @@
406 442
407 443 $address = CustomerAddresses::query()->findOrFail($id);
408 444
409 445 $customer = \FluentCart\Api\Resource\CustomerResource::getCurrentCustomer();
446 +
410 447 if (empty($customer) || $customer->id != $address->customer_id) {
411 - $this->sendError([
448 + return $this->sendError([
412 449 'message' => __('You are not authorized to delete this address', 'fluent-cart')
413 450 ]);
414 451 }
415 452
@@ -470,8 +507,20 @@
470 507 }
471 508 }
472 509
473 510 $address['type'] = Arr::get($data, 'type');
511 +
512 + if (empty($address['name'])) {
513 + if (!empty($address['full_name'])) {
514 + $address['name'] = $address['full_name'];
515 + } else {
516 + $firstName = trim(Arr::get($address, 'first_name', ''));
517 + $lastName = trim(Arr::get($address, 'last_name', ''));
518 + if ($firstName || $lastName) {
519 + $address['name'] = trim($firstName . ' ' . $lastName);
520 + }
521 + }
522 + }
474 523
475 524 return $address;
476 525 }
477 526