Files
WooNooW/includes/Api/StoreController.php
dwindown dd2ff2074f fix: Login logo 401, link focus styles, payment/shipping active colors
## 1. Fix Logo 401 Error on Login 

**Issue:** Logo image returns 401 Unauthorized on login page

**Root Cause:** `/store/settings` endpoint requires authentication

**Solution:** Created public branding endpoint
```php
// GET /woonoow/v1/store/branding (PUBLIC)
public function get_branding() {
    return [
        'store_name' => get_option('blogname'),
        'store_logo' => get_option('woonoow_store_logo'),
        'store_icon' => get_option('woonoow_store_icon'),
        'store_tagline' => get_option('woonoow_store_tagline'),
    ];
}
```

**Frontend:** Updated Login.tsx to use `/store/branding` instead

**Result:** Logo loads without authentication 

---

## 2. Override WordPress Link Focus Styles 

**Issue:** WordPress common.css applies focus/active styles to links

**Solution:** Added CSS override
```css
a:focus,
a:active {
  outline: none !important;
  box-shadow: none !important;
}
```

**Result:** Clean focus states, no WordPress interference

---

## 3. Active Color for Manual Payment Methods 

**Issue:** Manual payments use static gray icon, online payments use green/primary

**Solution:** Applied same active color logic
```tsx
<div className={`p-2 rounded-lg ${
  gateway.enabled
    ? 'bg-green-500/20 text-green-500'
    : 'bg-primary/10 text-primary'
}`}>
  <Banknote className="h-5 w-5" />
</div>
```

**Result:**
-  Enabled = Green background + green icon
-  Disabled = Primary background + primary icon
-  Consistent with online payments

---

## 4. Active Color for Shipping Icons 

**Issue:** Shipping icons always gray, no visual indicator of enabled state

**Solution:** Applied active color to all shipping icons
- Zone summary view
- Desktop accordion view
- Mobile accordion view

```tsx
<div className={`p-2 rounded-lg ${
  rate.enabled
    ? 'bg-green-500/20 text-green-500'
    : 'bg-primary/10 text-primary'
}`}>
  <Truck className="h-4 w-4" />
</div>
```

**Result:**
-  Enabled shipping = Green icon
-  Disabled shipping = Primary icon
-  Consistent visual language across payments & shipping

---

## 5. Notification Strategy 

**Acknowledged:** Clean structure, ready for implementation

---

## Summary

 Public branding endpoint (no auth required)
 Logo loads on login page
 WordPress link focus styles overridden
 Manual payments have active colors
 Shipping methods have active colors
 Consistent visual language (green = active, primary = inactive)

**Visual Consistency Achieved:**
- Payments (manual & online) ✓
- Shipping methods ✓
- All use same color system ✓
2025-11-11 00:03:14 +07:00

253 lines
7.6 KiB
PHP

<?php
/**
* Store REST API Controller
*
* Provides REST endpoints for store settings management.
*
* @package WooNooW
*/
namespace WooNooW\API;
use WooNooW\Compat\StoreSettingsProvider;
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 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]
);
}
}
/**
* Check permission
*
* @return bool True if user has permission
*/
public function check_permission() {
return current_user_can('manage_woocommerce');
}
}