$termId]); as_enqueue_async_action('aikanen_export_category', ['term_id' => $termId]); } // Export a category to Aikanen as service group public function exportCategory(int $termId): void { $term = get_term($termId, 'product_cat'); if (!$term || is_wp_error($term)) { // Product (no longer) found on WooCommerce return; } $aikanenId = $this->categoryMapper->getAikanenId($term); $payload = $this->categoryMapper->toAikanen($term); if ($aikanenId) { // Update if category already exists in Aikanen $this->api->put("/service_groups/{$aikanenId}", $payload); } else { // Create as new if doesn't exist in Aikanen $response = $this->api->post('/service_groups', $payload); $this->categoryMapper->setAikanenId($term, $response['data']['id']); } } // Export categories to Aikanen in bulk public function handleBulkExport(string $redirectTo, string $action, array $termIds): string { if ($action !== 'export_to_aikanen') { return $redirectTo; } foreach ($termIds as $termId) { as_enqueue_async_action('aikanen_export_category', ['term_id' => (int) $termId]); } return add_query_arg('aikanen_exported_categories', count($termIds), $redirectTo); } public function addBulkAction(array $actions): array { $actions['export_to_aikanen'] = __('Export to Aikanen', 'aikanen'); return $actions; } // Remove sync from category public function handleDesync(): void { $termId = absint(wp_unslash($_GET['term_id'] ?? 0)); if ( !$termId || !current_user_can('manage_woocommerce') || !check_admin_referer('aikanen_desync_category_' . $termId) ) { wp_die('Unauthorized.'); } $term = get_term($termId, 'product_cat'); if (!$term || is_wp_error($term)) { wp_die('Category not found.'); } $this->categoryMapper->clearAikanenId($term); wp_safe_redirect(admin_url('edit-tags.php?taxonomy=product_cat&post_type=product')); exit; } }