| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Actions\Controller\ProductActions; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Product\ProductOperations; |
| 6 |
use SyncBasalam\Actions\Controller\ActionController; |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
class DisconnectProduct extends ActionController |
| 10 |
{ |
| 11 |
public function __invoke() |
| 12 |
{ |
| 13 |
$productId = isset($_POST['product_id']) ? sanitize_text_field(wp_unslash($_POST['product_id'])) : null; |
| 14 |
|
| 15 |
$productOperations = syncBasalamContainer()->get(ProductOperations::class); |
| 16 |
|
| 17 |
if (isset($_POST['cat_id'])) { |
| 18 |
$categoryIds = sanitize_text_field(wp_unslash($_POST['cat_id'])); |
| 19 |
|
| 20 |
if (strpos($categoryIds, ',') !== false) { |
| 21 |
$categoryIds = explode(',', $categoryIds); |
| 22 |
} else { |
| 23 |
$categoryIds = [$categoryIds]; |
| 24 |
} |
| 25 |
} else { |
| 26 |
$categoryIds = null; |
| 27 |
} |
| 28 |
|
| 29 |
if ($productId) { |
| 30 |
$result = $productOperations->disconnectProduct($productId); |
| 31 |
} |
| 32 |
|
| 33 |
if (!$result['success']) { |
| 34 |
wp_send_json_error(['message' => $result['message']], $result['status_code'] ?? 500); |
| 35 |
} |
| 36 |
|
| 37 |
wp_send_json_success(['message' => $result['message']], $result['status_code'] ?? 200); |
| 38 |
} |
| 39 |
} |
| 40 |
|