Commit Graph

12 Commits

Author SHA1 Message Date
Dwindi Ramadhana
3357fbfcf1 feat: Dynamic SPA slug, field label storage, and SPA frontpage support (WIP) 2026-01-10 00:50:32 +07:00
Dwindi Ramadhana
45fcbf9d29 feat: migrate from HashRouter to BrowserRouter for SEO
Phase 1: WordPress Rewrite Rules
- Add rewrite rule for /store/* to serve SPA page
- Add use_browser_router setting toggle (default: true)
- Flush rewrite rules on settings change

Phase 2: React Router Migration
- Add BrowserRouter with basename from WordPress config
- Pass basePath and useBrowserRouter to frontend
- Conditional router based on setting

Phase 3: Hash Route Migration
- Update EmailManager.php reset password URL
- Update EmailRenderer.php login URL
- Update TemplateOverride.php WC redirects
- All routes now use path format by default

This enables proper SEO indexing as search engines
can now crawl individual product/page URLs.
2026-01-03 20:01:32 +07:00
Dwindi Ramadhana
82399d4ddf fix: WP-Admin CSS conflicts and add-to-cart redirect
- Fix CSS conflicts between WP-Admin and SPA (radio buttons, chart text)
- Add Tailwind important selector scoped to #woonoow-admin-app
- Remove overly aggressive inline SVG styles from Assets.php
- Add targeted WordPress admin CSS overrides in index.css
- Fix add-to-cart redirect to use woocommerce_add_to_cart_redirect filter
- Let WooCommerce handle cart operations natively for proper session management
- Remove duplicate tailwind.config.cjs
2025-12-31 14:06:04 +07:00
Dwindi Ramadhana
fe98e6233d 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
2025-12-30 20:33:15 +07:00
Dwindi Ramadhana
012effd11d feat: Add dedicated SPA page selection (WooCommerce-style)
Problem: Shortcode 'island' architecture is fragile and theme-dependent
- SPA div buried deep in theme structure (body > div.wp-site-blocks > main > div#app)
- Theme and plugins can intervene at any level
- Different themes have different structures
- Breaks easily with theme changes

Solution: Dedicated page-based SPA system (like WooCommerce)
- Add page selection in Appearance > General settings
- Store page IDs for Shop, Cart, Checkout, Account
- Full-body SPA rendering on designated pages
- No theme interference

Changes:
- AppearanceController.php:
  * Added spa_pages field to general settings
  * Stores page IDs for each SPA type (shop/cart/checkout/account)

- TemplateOverride.php:
  * Added is_spa_page() method to check designated pages
  * Use blank template for designated pages (priority over legacy)
  * Remove theme elements for designated pages

- Assets.php:
  * Added is_spa_page() check before mode/shortcode checks
  * Load assets on designated pages regardless of mode

Architecture:
- Designated pages render directly to <body>
- No theme wrapper/structure interference
- Clean full-page SPA experience
- Works with ANY theme consistently

Next: Add UI in admin-spa General tab for page selection
2025-12-30 19:42:16 +07:00
Dwindi Ramadhana
b2ac2996f9 fix: Detect shortcode on WooCommerce Shop page correctly
Problem: Customer SPA not loading on Shop page despite having [woonoow_shop] shortcode
Root Cause: WooCommerce Shop page is an archive page - when visiting /shop/, WordPress sets $post to the first product in the loop, not the Shop page itself. So shortcode check was checking product content instead of Shop page content.

Solution: Add special handling for is_shop() - get Shop page content directly using woocommerce_shop_page_id option and check for shortcode there.

Changes:
- Check is_shop() first before checking $post content
- Get Shop page via get_option('woocommerce_shop_page_id')
- Check shortcode on actual Shop page content
- Falls back to regular $post check for other pages

Result:
 Shop page shortcode detection now works correctly
 Customer SPA will load on Shop page with [woonoow_shop] shortcode
 Other WooCommerce pages (Cart, Checkout, Account) still work
2025-12-30 18:02:48 +07:00
Dwindi Ramadhana
b6a0a66000 fix: Add SPA mounting point for full mode
Problem: Customer SPA not loading in 'full' mode
Root Cause: In full mode, SPA loads on WooCommerce pages without shortcodes, so there's no #woonoow-customer-app div for React to mount to

Solution: Inject mounting point div when in full mode via woocommerce_before_main_content hook

Changes:
- Added inject_spa_mount_point() method
- Hooks into woocommerce_before_main_content when in full mode
- Only injects if mount point doesn't exist from shortcode

Result:
 Full mode now has mounting point on WooCommerce pages
 Shortcode mode still works with shortcode-provided divs
 Customer SPA can now initialize properly
2025-12-30 17:54:12 +07:00
Dwindi Ramadhana
3260c8c112 debug: Add detailed logging to customer SPA asset loading
Added comprehensive logging to track:
- should_load_assets() decision flow
- SPA mode setting
- Post ID and content
- Shortcode detection
- Asset enqueue URLs
- Dev vs production mode

This will help identify why customer SPA is not loading.
2025-12-30 17:51:04 +07:00
Dwindi Ramadhana
0609c6e3d8 fix: Customer SPA loading and optimize production build size
Problem 1: Customer SPA not loading (stuck on 'Loading...')
Root Cause: Missing type='module' attribute on customer SPA script tag
Solution: Added script_loader_tag filter to inject type='module' for ES modules

Problem 2: Production zip too large (21-41MB)
Root Cause: Build script included unnecessary files (dist folder, fonts, .vite, test files, archives)
Solution:
- Exclude entire customer-spa and admin-spa directories from rsync
- Manually copy only app.js and app.css for both SPAs
- Exclude dist/, archive/, test-*.php, check-*.php files
- Simplified Frontend/Assets.php to always load app.js/app.css directly (no manifest needed)

Changes:
- includes/Frontend/Assets.php:
  * Added type='module' to customer SPA script (both manifest and fallback paths)
  * Removed manifest logic, always load app.js and app.css directly
- build-production.sh:
  * Exclude customer-spa and admin-spa directories completely
  * Manually copy only dist/app.js and dist/app.css
  * Exclude dist/, archive/, test files

Result:
 Customer SPA loads with type='module' support
 Production zip reduced from 21-41MB to 1.6MB
 Only essential files included (app.js + app.css for both SPAs)
 Clean production package without dev artifacts

Package contents:
- Customer SPA: 480K (app.js) + 52K (app.css) = 532K
- Admin SPA: 2.6M (app.js) + 76K (app.css) = 2.7M
- PHP Backend: ~500K
- Total: 1.6M (compressed)
2025-12-30 17:48:09 +07:00
Dwindi Ramadhana
447ca501c7 fix: Generate Vite manifest for customer SPA loading
Problem: Customer SPA stuck on 'Loading...' message after installation
Root Cause: Vite build wasn't generating manifest.json, causing WordPress asset loader to fall back to direct app.js loading without proper module configuration

Solution:
1. Added manifest: true to both SPA vite configs
2. Updated Assets.php to look for manifest in correct location (.vite/manifest.json)
3. Rebuilt both SPAs with manifest generation

Changes:
- customer-spa/vite.config.ts: Added manifest: true
- admin-spa/vite.config.ts: Added manifest: true
- includes/Frontend/Assets.php: Updated manifest path from 'manifest.json' to '.vite/manifest.json'

Build Output:
- Customer SPA: dist/.vite/manifest.json generated
- Admin SPA: dist/.vite/manifest.json generated
- Production zip: 10M (includes manifest files)

Result:
 Customer SPA now loads correctly via manifest
 Admin SPA continues to work
 Proper asset loading with CSS and JS from manifest
 Production package ready for deployment
2025-12-30 17:26:18 +07:00
Dwindi Ramadhana
9ac09582d2 feat: implement header/footer visibility controls for checkout and thankyou pages
- Created LayoutWrapper component to conditionally render header/footer based on route
- Created MinimalHeader component (logo only)
- Created MinimalFooter component (trust badges + policy links)
- Created usePageVisibility hook to get visibility settings per page
- Wrapped ClassicLayout with LayoutWrapper for conditional rendering
- Header/footer visibility now controlled directly in React SPA
- Settings: show/minimal/hide for both header and footer
- Background color support for checkout and thankyou pages
2025-12-25 22:20:48 +07:00
Dwindi Ramadhana
f397ef850f feat: Add product images support with WP Media Library integration
- Add WP Media Library integration for product and variation images
- Support images array (URLs) conversion to attachment IDs
- Add images array to API responses (Admin & Customer SPA)
- Implement drag-and-drop sortable images in Admin product form
- Add image gallery thumbnails in Customer SPA product page
- Initialize WooCommerce session for guest cart operations
- Fix product variations and attributes display in Customer SPA
- Add variation image field in Admin SPA

Changes:
- includes/Api/ProductsController.php: Handle images array, add to responses
- includes/Frontend/ShopController.php: Add images array for customer SPA
- includes/Frontend/CartController.php: Initialize WC session for guests
- admin-spa/src/lib/wp-media.ts: Add openWPMediaGallery function
- admin-spa/src/routes/Products/partials/tabs/GeneralTab.tsx: WP Media + sortable images
- admin-spa/src/routes/Products/partials/tabs/VariationsTab.tsx: Add variation image field
- customer-spa/src/pages/Product/index.tsx: Add gallery thumbnails display
2025-11-26 16:18:43 +07:00