feat(shop): product list widget AJAX pager 1:1 with zibll
Expose REST /shop/frontend/widgets/products, shared query_payload, ajax-list load-more markup, and product widget styles.
This commit is contained in:
1 parent
c2be36acd7
commit
5fa902304b
3 files changed
+349
-203
No files matched your search
@@ -379,6 +379,13 @@ class ShopController extends ControllerBase {
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
|
||||
// Product list widget AJAX (zibll ajax_widget_ui product lists).
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/widgets/products', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_frontend_widget_products'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/revenue', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_frontend_revenue'],
|
||||
|
||||
@@ -509,6 +509,40 @@ trait ShopControllerFrontendFlowOperations {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /shop/frontend/widgets/products — product list widget AJAX pager.
|
||||
*/
|
||||
public function get_frontend_widget_products(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Widgets\WidgetProductList')) {
|
||||
return $this->error('商品组件不可用', 500);
|
||||
}
|
||||
|
||||
$instance = [
|
||||
'per_page' => max(1, min(50, (int) ($request->get_param('per_page') ?? 8))),
|
||||
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
|
||||
'order' => sanitize_key((string) ($request->get_param('order') ?? 'DESC')),
|
||||
'cat_ids' => sanitize_text_field((string) ($request->get_param('cat_ids') ?? '')),
|
||||
'tag_ids' => sanitize_text_field((string) ($request->get_param('tag_ids') ?? '')),
|
||||
'discount_ids' => sanitize_text_field((string) ($request->get_param('discount_ids') ?? '')),
|
||||
'exclude_cat' => !empty($request->get_param('exclude_cat')) ? 1 : 0,
|
||||
'style' => sanitize_key((string) ($request->get_param('style') ?? 'default')),
|
||||
'paginate' => sanitize_key((string) ($request->get_param('paginate') ?? 'ajax')),
|
||||
];
|
||||
$page = max(1, (int) ($request->get_param('page') ?? $request->get_param('paged') ?? 1));
|
||||
$payload = \AKSRT\Widgets\WidgetProductList::query_payload($instance, $page);
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'html' => (string) ($payload['html'] ?? ''),
|
||||
'paginate_html' => (string) ($payload['paginate_html'] ?? ''),
|
||||
'has_more' => !empty($payload['has_more']),
|
||||
'page' => (int) ($payload['page'] ?? $page),
|
||||
'max_pages' => (int) ($payload['max_pages'] ?? 1),
|
||||
'total' => (int) ($payload['total'] ?? 0),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render cat filter bar HTML for AJAX header replace.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user