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
This commit is contained in:
Dwindi Ramadhana
2025-11-26 16:18:43 +07:00
parent 909bddb23d
commit f397ef850f
69 changed files with 12481 additions and 156 deletions

View File

@@ -88,35 +88,44 @@ class ApiClient {
}
}
// Export singleton instance
export const api = new ApiClient();
// Export API endpoints
export const endpoints = {
// Shop
products: '/shop/products',
product: (id: number) => `/shop/products/${id}`,
categories: '/shop/categories',
search: '/shop/search',
// Cart
cart: '/cart',
cartAdd: '/cart/add',
cartUpdate: '/cart/update',
cartRemove: '/cart/remove',
cartCoupon: '/cart/apply-coupon',
// Checkout
checkoutCalculate: '/checkout/calculate',
checkoutCreate: '/checkout/create-order',
paymentMethods: '/checkout/payment-methods',
shippingMethods: '/checkout/shipping-methods',
// Account
orders: '/account/orders',
order: (id: number) => `/account/orders/${id}`,
downloads: '/account/downloads',
profile: '/account/profile',
password: '/account/password',
addresses: '/account/addresses',
// API endpoints
const endpoints = {
shop: {
products: '/shop/products',
product: (id: number) => `/shop/products/${id}`,
categories: '/shop/categories',
search: '/shop/search',
},
cart: {
get: '/cart',
add: '/cart/add',
update: '/cart/update',
remove: '/cart/remove',
applyCoupon: '/cart/apply-coupon',
removeCoupon: '/cart/remove-coupon',
},
checkout: {
calculate: '/checkout/calculate',
create: '/checkout/create-order',
paymentMethods: '/checkout/payment-methods',
shippingMethods: '/checkout/shipping-methods',
},
account: {
orders: '/account/orders',
order: (id: number) => `/account/orders/${id}`,
downloads: '/account/downloads',
profile: '/account/profile',
password: '/account/password',
addresses: '/account/addresses',
},
};
// Create singleton instance with endpoints
const client = new ApiClient();
// Export as apiClient with endpoints attached
export const apiClient = Object.assign(client, { endpoints });
// Also export individual pieces for convenience
export const api = client;
export { endpoints };