## ✅ Issue 1: Customers Submenu Missing in WP-Admin **Problem:** Tax and Customer submenus only visible in standalone mode **Root Cause:** PHP navigation registry did not include Customers **Fixed:** Added Customers to NavigationRegistry.php settings children **Result:** Customers submenu now shows in all modes ## ✅ Issue 2: App Logo/Title in Topbar **Problem:** Should show logo → store name → "WooNooW" fallback **Fixed:** Header component now: - Fetches branding from /store/branding endpoint - Shows logo image if available - Falls back to store name text - Updates on store settings change event **Result:** Proper branding hierarchy in app header ## ✅ Issue 3: Zone Card Header Density on Mobile **Problem:** "Indonesia Addons" row with 3 icons too cramped on mobile **Fixed:** Shipping.tsx zone card header: - Reduced gap from gap-3 to gap-2/gap-1 on mobile - Smaller font size on mobile (text-sm md:text-lg) - Added min-w-0 for proper text truncation - flex-shrink-0 on icon buttons **Result:** Better mobile spacing and readability ## ✅ Issue 4: Go to WP Admin Button **Problem:** Should show in standalone mode, not wp-admin **Fixed:** More page now shows "Go to WP Admin" button: - Only in standalone mode - Before Logout button - Links to /wp-admin **Result:** Easy access to WP Admin from standalone mode ## ✅ Issue 5: Customer Settings 403 Error **Problem:** Permission check failing for customer-settings endpoint **Fixed:** StoreController.php check_permission(): - Added fallback: manage_woocommerce OR manage_options - Ensures administrators always have access **Result:** Customer Settings page loads successfully ## ✅ Issue 6: Dark Mode Logo Upload Field **Problem:** No UI to upload dark mode logo **Fixed:** Store settings page now has: - "Store logo (Light mode)" field - "Store logo (Dark mode)" field (optional) - Backend support in StoreSettingsProvider - Full save/load functionality **Result:** Users can upload separate logos for light/dark modes ## ✅ Issue 7: Login Card Background Too Dark **Problem:** Login card same color as background in dark mode **Fixed:** Login.tsx card styling: - Changed from dark:bg-gray-800 (solid) - To dark:bg-gray-900/50 (semi-transparent) - Added backdrop-blur-xl for glass effect - Added border for definition **Result:** Login card visually distinct with modern glass effect --- ## Summary **All 7 Issues Resolved:** 1. ✅ Customers submenu in all modes 2. ✅ Logo/title hierarchy in topbar 3. ✅ Mobile zone card spacing 4. ✅ Go to WP Admin in standalone 5. ✅ Customer Settings permission fix 6. ✅ Dark mode logo upload field 7. ✅ Lighter login card background **Files Modified:** - NavigationRegistry.php - Added Customers to nav - App.tsx - Logo/branding in header - Shipping.tsx - Mobile spacing - More/index.tsx - WP Admin button - StoreController.php - Permission fallback - Store.tsx - Dark logo field - StoreSettingsProvider.php - Dark logo backend - Login.tsx - Card background **Ready for production!** 🎉
342 lines
11 KiB
PHP
342 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Store REST API Controller
|
|
*
|
|
* Provides REST endpoints for store settings management.
|
|
*
|
|
* @package WooNooW
|
|
*/
|
|
|
|
namespace WooNooW\API;
|
|
|
|
use WooNooW\Compat\StoreSettingsProvider;
|
|
use WooNooW\Compat\CustomerSettingsProvider;
|
|
use WP_REST_Controller;
|
|
use WP_REST_Server;
|
|
use WP_REST_Request;
|
|
use WP_REST_Response;
|
|
use WP_Error;
|
|
|
|
class StoreController extends WP_REST_Controller {
|
|
|
|
/**
|
|
* Namespace
|
|
*/
|
|
protected $namespace = 'woonoow/v1';
|
|
|
|
/**
|
|
* Rest base
|
|
*/
|
|
protected $rest_base = 'store';
|
|
|
|
/**
|
|
* Register routes
|
|
*/
|
|
public function register_routes() {
|
|
// GET /woonoow/v1/store/branding (PUBLIC - for login page)
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/branding', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_branding'],
|
|
'permission_callback' => '__return_true', // Public endpoint
|
|
],
|
|
]);
|
|
|
|
// GET /woonoow/v1/store/settings
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/settings', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_settings'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// POST /woonoow/v1/store/settings
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/settings', [
|
|
[
|
|
'methods' => WP_REST_Server::EDITABLE,
|
|
'callback' => [$this, 'save_settings'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// GET /woonoow/v1/store/countries
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/countries', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_countries'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// GET /woonoow/v1/store/timezones
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/timezones', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_timezones'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// GET /woonoow/v1/store/currencies
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/currencies', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_currencies'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// GET /woonoow/v1/store/customer-settings
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/customer-settings', [
|
|
[
|
|
'methods' => WP_REST_Server::READABLE,
|
|
'callback' => [$this, 'get_customer_settings'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
|
|
// POST /woonoow/v1/store/customer-settings
|
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/customer-settings', [
|
|
[
|
|
'methods' => WP_REST_Server::EDITABLE,
|
|
'callback' => [$this, 'save_customer_settings'],
|
|
'permission_callback' => [$this, 'check_permission'],
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get store branding (PUBLIC - for login page)
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response Response object
|
|
*/
|
|
public function get_branding(WP_REST_Request $request) {
|
|
$branding = [
|
|
'store_name' => get_option('blogname', 'WooNooW'),
|
|
'store_logo' => get_option('woonoow_store_logo', ''),
|
|
'store_icon' => get_option('woonoow_store_icon', ''),
|
|
'store_tagline' => get_option('woonoow_store_tagline', ''),
|
|
];
|
|
|
|
$response = rest_ensure_response($branding);
|
|
$response->header('Cache-Control', 'max-age=300'); // Cache for 5 minutes
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Get store settings
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function get_settings(WP_REST_Request $request) {
|
|
try {
|
|
$settings = StoreSettingsProvider::get_settings();
|
|
|
|
$response = rest_ensure_response($settings);
|
|
$response->header('Cache-Control', 'max-age=60');
|
|
|
|
return $response;
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'get_settings_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save store settings
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function save_settings(WP_REST_Request $request) {
|
|
$settings = $request->get_json_params();
|
|
|
|
if (empty($settings)) {
|
|
return new WP_Error(
|
|
'missing_settings',
|
|
'No settings provided',
|
|
['status' => 400]
|
|
);
|
|
}
|
|
|
|
try {
|
|
$result = StoreSettingsProvider::save_settings($settings);
|
|
|
|
if (!$result) {
|
|
return new WP_Error(
|
|
'save_failed',
|
|
'Failed to save settings',
|
|
['status' => 500]
|
|
);
|
|
}
|
|
|
|
return rest_ensure_response([
|
|
'success' => true,
|
|
'message' => 'Settings saved successfully',
|
|
'settings' => StoreSettingsProvider::get_settings(),
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'save_settings_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get countries
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function get_countries(WP_REST_Request $request) {
|
|
try {
|
|
$countries = StoreSettingsProvider::get_countries();
|
|
|
|
$response = rest_ensure_response($countries);
|
|
$response->header('Cache-Control', 'max-age=3600'); // Cache for 1 hour
|
|
|
|
return $response;
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'get_countries_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get timezones
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function get_timezones(WP_REST_Request $request) {
|
|
try {
|
|
$timezones = StoreSettingsProvider::get_timezones();
|
|
|
|
$response = rest_ensure_response($timezones);
|
|
$response->header('Cache-Control', 'max-age=3600'); // Cache for 1 hour
|
|
|
|
return $response;
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'get_timezones_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get currencies
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function get_currencies(WP_REST_Request $request) {
|
|
try {
|
|
$currencies = StoreSettingsProvider::get_currencies();
|
|
|
|
$response = rest_ensure_response($currencies);
|
|
$response->header('Cache-Control', 'max-age=3600'); // Cache for 1 hour
|
|
|
|
return $response;
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'get_currencies_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get customer settings
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function get_customer_settings(WP_REST_Request $request) {
|
|
try {
|
|
$settings = CustomerSettingsProvider::get_settings();
|
|
|
|
$response = rest_ensure_response($settings);
|
|
$response->header('Cache-Control', 'max-age=60');
|
|
|
|
return $response;
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'get_customer_settings_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save customer settings
|
|
*
|
|
* @param WP_REST_Request $request Request object
|
|
* @return WP_REST_Response|WP_Error Response object or error
|
|
*/
|
|
public function save_customer_settings(WP_REST_Request $request) {
|
|
try {
|
|
$settings = $request->get_json_params();
|
|
|
|
if (empty($settings)) {
|
|
return new WP_Error(
|
|
'invalid_settings',
|
|
__('Invalid settings data', 'woonoow'),
|
|
['status' => 400]
|
|
);
|
|
}
|
|
|
|
$updated = CustomerSettingsProvider::update_settings($settings);
|
|
|
|
if (!$updated) {
|
|
return new WP_Error(
|
|
'update_failed',
|
|
__('Failed to update customer settings', 'woonoow'),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
|
|
// Return updated settings
|
|
$new_settings = CustomerSettingsProvider::get_settings();
|
|
|
|
return new WP_REST_Response([
|
|
'success' => true,
|
|
'message' => __('Customer settings updated successfully', 'woonoow'),
|
|
'settings' => $new_settings,
|
|
], 200);
|
|
|
|
} catch (\Exception $e) {
|
|
return new WP_Error(
|
|
'save_customer_settings_failed',
|
|
$e->getMessage(),
|
|
['status' => 500]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if user has permission
|
|
*
|
|
* @return bool True if user has permission
|
|
*/
|
|
public function check_permission() {
|
|
// Check WooCommerce capability first, fallback to manage_options
|
|
return current_user_can('manage_woocommerce') || current_user_can('manage_options');
|
|
}
|
|
}
|