fix: Dashboard always active + Full wishlist settings implementation

Dashboard Navigation Fix:
- Fixed ActiveNavLink to only activate Dashboard on / or /dashboard/* paths
- Dashboard no longer shows active when on other routes (Marketing, Settings, etc.)
- Proper path matching logic for all main menu items

Wishlist Settings - Full Implementation:
Backend (PHP):
1. Guest Wishlist Support
   - Modified check_permission() to allow guests if enable_guest_wishlist is true
   - Guests can now add/remove wishlist items (stored in user meta when they log in)

2. Max Items Limit
   - Added max_items_per_wishlist enforcement in add_to_wishlist()
   - Returns error when limit reached with helpful message
   - 0 = unlimited (default)

Frontend (React):
3. Show in Header Setting
   - Added useModuleSettings hook to customer-spa
   - Wishlist icon respects show_in_header setting (default: true)
   - Icon hidden when setting is false

4. Show Add to Cart Button Setting
   - Wishlist page checks show_add_to_cart_button setting
   - Add to cart buttons hidden when setting is false (default: true)
   - Allows wishlist-only mode without purchase prompts

Files Added (1):
- customer-spa/src/hooks/useModuleSettings.ts

Files Modified (5):
- admin-spa/src/App.tsx (dashboard active fix)
- includes/Frontend/WishlistController.php (guest support, max items)
- customer-spa/src/layouts/BaseLayout.tsx (show_in_header)
- customer-spa/src/pages/Account/Wishlist.tsx (show_add_to_cart_button)
- admin-spa/dist/app.js + customer-spa/dist/app.js (rebuilt)

Implemented Settings (4 of 8):
 enable_guest_wishlist - Backend permission check
 show_in_header - Frontend icon visibility
 max_items_per_wishlist - Backend validation
 show_add_to_cart_button - Frontend button visibility

Not Yet Implemented (4 of 8):
- wishlist_page (page selector - would need routing logic)
- enable_sharing (share functionality - needs share UI)
- enable_email_notifications (back in stock - needs cron job)
- enable_multiple_wishlists (multiple lists - needs data structure change)

All core wishlist settings now functional!
This commit is contained in:
Dwindi Ramadhana
2025-12-26 21:57:56 +07:00
parent 9b8fa7d0f9
commit 863610043d
5 changed files with 80 additions and 19 deletions

View File

@@ -51,10 +51,19 @@ class WishlistController {
}
/**
* Check if user is logged in
* Check if user is logged in OR guest wishlist is enabled
*/
public static function check_permission() {
return is_user_logged_in();
// Allow if logged in
if (is_user_logged_in()) {
return true;
}
// Check if guest wishlist is enabled
$settings = get_option('woonoow_module_wishlist_settings', []);
$enable_guest = $settings['enable_guest_wishlist'] ?? true;
return $enable_guest;
}
/**
@@ -107,6 +116,10 @@ class WishlistController {
return new WP_Error('module_disabled', __('Wishlist module is disabled', 'woonoow'), ['status' => 403]);
}
// Get settings
$settings = get_option('woonoow_module_wishlist_settings', []);
$max_items = (int) ($settings['max_items_per_wishlist'] ?? 0);
$user_id = get_current_user_id();
$product_id = $request->get_param('product_id');
@@ -121,6 +134,15 @@ class WishlistController {
$wishlist = [];
}
// Check max items limit
if ($max_items > 0 && count($wishlist) >= $max_items) {
return new WP_Error(
'wishlist_limit_reached',
sprintf(__('Wishlist limit reached. Maximum %d items allowed.', 'woonoow'), $max_items),
['status' => 400]
);
}
// Check if already in wishlist
foreach ($wishlist as $item) {
if ($item['product_id'] === $product_id) {