feat(api): Add CustomersController with full CRUD operations

Backend implementation for Customer module

Created CustomersController.php:
 GET /customers - List with pagination, search, role filter
 GET /customers/{id} - Get single customer with full details
 POST /customers - Create new customer with validation
 PUT /customers/{id} - Update customer data
 DELETE /customers/{id} - Delete customer (with safety checks)
 GET /customers/search - Autocomplete search

Features:
- Full WooCommerce integration (WC_Customer)
- Billing and shipping address management
- Order stats (total_orders, total_spent)
- Email uniqueness validation
- Username auto-generation from email
- Password generation if not provided
- Role-based permissions (list_users, create_users, etc.)
- Cannot delete current user (safety)
- Optional new account email notification

Data format:
- List: Basic customer info (id, name, email, registered)
- Detail: Full data including billing, shipping, stats
- Search: Minimal data for autocomplete (id, name, email)

Registered routes in Routes.php:
- Added CustomersController import
- Registered all customer endpoints

Next: Frontend API client and CRUD pages
This commit is contained in:
dwindown
2025-11-20 22:40:59 +07:00
parent 3ed2a081e5
commit 829d9d0d8f
2 changed files with 440 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ use WooNooW\Api\NotificationsController;
use WooNooW\Api\ActivityLogController;
use WooNooW\Api\ProductsController;
use WooNooW\Api\CouponsController;
use WooNooW\Api\CustomersController;
class Routes {
public static function init() {
@@ -112,6 +113,9 @@ class Routes {
// Coupons controller
CouponsController::register_routes();
// Customers controller
CustomersController::register_routes();
});
}
}