PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.6
ووسلام – همگام سازی ووکامرس و باسلام v1.8.6
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Actions / Controller / CategoryActions / CreateCategoryMap.php

CreateCategoryMap.php in ووسلام – همگام سازی ووکامرس و باسلام 1.8.6, at includes/Actions/Controller/CategoryActions/CreateCategoryMap.php

48 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Actions\Controller\CategoryActions;
4
5 use SyncBasalam\Admin\Product\Category\CategoryMapping;
6 use SyncBasalam\Actions\Controller\ActionController;
7
8 defined('ABSPATH') || exit;
9 class CreateCategoryMap extends ActionController
10 {
11 public function __invoke()
12 {
13 if (!current_user_can('manage_options')) {
14 wp_die('Unauthorized');
15 }
16
17 $wooCategoryId = intval($_POST['woo_category_id']);
18 $wooCategoryName = sanitize_text_field($_POST['woo_category_name']);
19 $basalamCategoryIds = isset($_POST['basalam_category_ids']) ? $_POST['basalam_category_ids'] : null;
20 $basalamCategoryName = sanitize_text_field($_POST['basalam_category_name']);
21
22 if (!$wooCategoryId || !$basalamCategoryIds || !is_array($basalamCategoryIds)) {
23 wp_send_json_error('Invalid category data');
24
25 return;
26 }
27
28 $basalamCategoryIds = array_map('intval', $basalamCategoryIds);
29
30 try {
31 $result = CategoryMapping::createCategoryMapping(
32 $wooCategoryId,
33 $wooCategoryName,
34 $basalamCategoryIds,
35 $basalamCategoryName
36 );
37
38 if ($result) {
39 wp_send_json_success('Mapping created successfully');
40 } else {
41 wp_send_json_error('Error creating mapping');
42 }
43 } catch (\Exception $e) {
44 wp_send_json_error($e->getMessage());
45 }
46 }
47 }
48