| @@ -123,8 +123,14 @@ | ||
| 123 | 123 | |
| 124 | 124 | // Assign the customer ID to the data array |
| 125 | 125 | $data['customer_id'] = $id; |
| 126 | 126 | |
| 127 | + // Request::getSafe() null-fills sanitize-map keys the client omitted; | |
| 128 | + // label is nullable at validation but NOT NULL DEFAULT '' at the column. | |
| 129 | + if (!isset($data['label'])) { | |
| 130 | + $data['label'] = ''; | |
| 131 | + } | |
| 132 | + | |
| 127 | 133 | $data = static::normalizeBusinessFields($data); |
| 128 | 134 | $data = static::mergeAddressMetaFields($data); |
| 129 | 135 | |
| 130 | 136 | // Create a new address record with the given data |
| @@ -307,9 +313,9 @@ | ||
| 307 | 313 | // Check if a valid ID is provided |
| 308 | 314 | if (!$id) { |
| 309 | 315 | return static::makeErrorResponse([ |
| 310 | 316 | ['code' => 403, 'message' => __('Please use a valid address ID!', 'fluent-cart')] |
| 311 | - ]); | |
| 317 | + ], 403); | |
| 312 | 318 | } |
| 313 | 319 | |
| 314 | 320 | // Retrieve the customer address using the ID |
| 315 | 321 | $customerAddress = static::getQuery()->find($id); |
| @@ -318,9 +324,9 @@ | ||
| 318 | 324 | // Check if the address is marked as primary |
| 319 | 325 | if ($customerAddress->is_primary) { |
| 320 | 326 | return static::makeErrorResponse([ |
| 321 | 327 | ['code' => 403, 'message' => __('Primary address cannot be deleted!', 'fluent-cart')] |
| 322 | - ]); | |
| 328 | + ], 403); | |
| 323 | 329 | } |
| 324 | 330 | // Get the count of addresses for this customer |
| 325 | 331 | $addressCount = static::getQuery()->where('customer_id', $customerAddress->customer_id)->count(); |
| 326 | 332 | |
| @@ -327,9 +333,9 @@ | ||
| 327 | 333 | // Check if there's only one address, do not allow deletion in that case |
| 328 | 334 | if ($addressCount <= 1) { |
| 329 | 335 | return static::makeErrorResponse([ |
| 330 | 336 | ['code' => 403, 'message' => __('At least one address must remain. Address deletion failed!', 'fluent-cart')] |
| 331 | - ]); | |
| 337 | + ], 403); | |
| 332 | 338 | } |
| 333 | 339 | |
| 334 | 340 | // If the address is not primary and there are multiple addresses, proceed with deletion |
| 335 | 341 | if ($customerAddress->delete()) { |
| @@ -338,14 +344,14 @@ | ||
| 338 | 344 | |
| 339 | 345 | // Return an error if the address is not found in the database |
| 340 | 346 | return static::makeErrorResponse([ |
| 341 | 347 | ['code' => 400, 'message' => __('Address deletion failed!', 'fluent-cart')] |
| 342 | - ]); | |
| 348 | + ], 400); | |
| 343 | 349 | } |
| 344 | 350 | |
| 345 | 351 | return static::makeErrorResponse([ |
| 346 | 352 | ['code' => 404, 'message' => __('Address not found in database, failed to remove.', 'fluent-cart')] |
| 347 | - ]); | |
| 353 | + ], 404); | |
| 348 | 354 | } |
| 349 | 355 | |
| 350 | 356 | /** |
| 351 | 357 | * Make primary address for the specified customer. |