feat: Affiliate program enrichment (Link Builder, Curated Collections, Smart Links)

This commit is contained in:
Dwindi Ramadhana
2026-06-03 14:04:17 +07:00
parent fd8eb38512
commit f8c733832e
22 changed files with 1348 additions and 10 deletions

View File

@@ -98,6 +98,13 @@ class ShopController
],
],
]);
// Get affiliate collection (public)
register_rest_route($namespace, '/shop/collections/(?P<slug>[a-zA-Z0-9-]+)', [
'methods' => 'GET',
'callback' => [__CLASS__, 'get_collection'],
'permission_callback' => '__return_true',
]);
}
/**
@@ -290,6 +297,57 @@ class ShopController
return new WP_REST_Response($products, 200);
}
/**
* Get affiliate collection by slug
*/
public static function get_collection(WP_REST_Request $request)
{
global $wpdb;
$slug = sanitize_title($request->get_param('slug'));
$collections_table = $wpdb->prefix . 'woonoow_affiliate_collections';
$collection = $wpdb->get_row($wpdb->prepare("SELECT * FROM $collections_table WHERE slug = %s", $slug));
if (!$collection) {
return new WP_Error('not_found', 'Collection not found', ['status' => 404]);
}
$product_ids = $collection->product_ids ? json_decode($collection->product_ids, true) : [];
if (!is_array($product_ids)) $product_ids = [];
$products = [];
if (!empty($product_ids)) {
$args = [
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'post__in' => $product_ids,
'orderby' => 'post__in',
];
$query = new \WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product = wc_get_product(get_the_ID());
if ($product) {
$products[] = self::format_product($product);
}
}
wp_reset_postdata();
}
}
$data = [
'id' => $collection->id,
'title' => $collection->title,
'description' => $collection->description,
'products' => $products
];
return new WP_REST_Response($data, 200);
}
/**
* Format product data for API response
*/