refactor: Simplify to single SPA entry page architecture

User feedback: 'SPA means Single Page, why 4 pages?'

Correct architecture:
- 1 SPA entry page (e.g., /store)
- SPA Mode determines initial route:
  * Full SPA → starts at shop page
  * Checkout Only → starts at cart page
  * Disabled → never loads
- React Router handles rest via /#/ routing

Changes:
- Admin UI: Changed from 4 page selectors to 1 SPA entry page
- Backend: spa_pages array → spa_page integer
- Template: Initial route based on spa_mode setting
- Simplified is_spa_page() checks (single ID comparison)

Benefits:
- User can set /store as homepage (Settings → Reading)
- Landing page → CTA → direct to cart/checkout
- Clean single entry point
- Mode controls behavior, not multiple pages

Example flow:
- Visit https://site.com/store
- Full SPA: loads shop, navigate via /#/product/123
- Checkout Only: loads cart, navigate via /#/checkout
- Homepage: set /store as homepage, SPA loads on site root

Next: Add direct-to-cart CTA with product parameter
This commit is contained in:
Dwindi Ramadhana
2025-12-30 20:33:15 +07:00
parent f054a78c5d
commit fe98e6233d
5 changed files with 45 additions and 131 deletions

View File

@@ -363,7 +363,7 @@ class Assets {
}
/**
* Check if current page is a designated SPA page
* Check if current page is the designated SPA page
*/
private static function is_spa_page() {
global $post;
@@ -371,17 +371,13 @@ class Assets {
return false;
}
// Get SPA page IDs from appearance settings
// Get SPA page ID from appearance settings
$appearance_settings = get_option('woonoow_appearance_settings', []);
$spa_pages = isset($appearance_settings['general']['spa_pages']) ? $appearance_settings['general']['spa_pages'] : [];
$spa_page_id = isset($appearance_settings['general']['spa_page']) ? $appearance_settings['general']['spa_page'] : 0;
// Check if current page matches any SPA page
$current_page_id = $post->ID;
foreach ($spa_pages as $page_type => $page_id) {
if ($page_id && $current_page_id == $page_id) {
return true;
}
// Check if current page matches the SPA page
if ($spa_page_id && $post->ID == $spa_page_id) {
return true;
}
return false;

View File

@@ -271,7 +271,7 @@ class TemplateOverride {
}
/**
* Check if current page is a designated SPA page
* Check if current page is the designated SPA page
*/
private static function is_spa_page() {
global $post;
@@ -279,17 +279,13 @@ class TemplateOverride {
return false;
}
// Get SPA page IDs from appearance settings
// Get SPA page ID from appearance settings
$appearance_settings = get_option('woonoow_appearance_settings', []);
$spa_pages = isset($appearance_settings['general']['spa_pages']) ? $appearance_settings['general']['spa_pages'] : [];
$spa_page_id = isset($appearance_settings['general']['spa_page']) ? $appearance_settings['general']['spa_page'] : 0;
// Check if current page matches any SPA page
$current_page_id = $post->ID;
foreach ($spa_pages as $page_type => $page_id) {
if ($page_id && $current_page_id == $page_id) {
return true;
}
// Check if current page matches the SPA page
if ($spa_page_id && $post->ID == $spa_page_id) {
return true;
}
return false;