PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.19
ووسلام – همگام سازی ووکامرس و باسلام v1.10.19
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 / ProductActions / CreateSingleProduct.php

CreateSingleProduct.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.19, at includes/Actions/Controller/ProductActions/CreateSingleProduct.php

55 lines 1.8 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\ProductActions;
4
5 use SyncBasalam\Admin\Product\ProductOperations;
6 use SyncBasalam\Actions\Controller\ActionController;
7 use SyncBasalam\Logger\Logger;
8 use SyncBasalam\Services\VendorSyncPolicy;
9
10 defined('ABSPATH') || exit;
11
12 class CreateSingleProduct extends ActionController
13 {
14 public function __invoke()
15 {
16 $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class);
17 if (!$vendorSyncPolicy->canCreate()) {
18 return wp_send_json_error(['message' => $vendorSyncPolicy->getRestrictionMessage(false)], 409);
19 }
20
21 $productOperations = syncBasalamContainer()->get(ProductOperations::class);
22
23 $productId = isset($_POST['product_id']) ? sanitize_text_field(wp_unslash($_POST['product_id'])) : null;
24
25 $catId = isset($_POST['cat_id']) ? sanitize_text_field(wp_unslash($_POST['cat_id'])) : '';
26
27 $catId = !empty($catId) ? explode(',', $catId) : [];
28
29 if (!$productId) {
30 wp_send_json_error(['message' => 'آیدی �
31 حصول الزا�
32 ی است.'], 400);
33 }
34
35 try {
36 $result = $productOperations->createNewProduct($productId, $catId);
37 } catch (\Exception $e) {
38 Logger::error("خطا در اضافه کردن �
39 حصول به باسلا�
40 : " . $e->getMessage(), [
41 'product_id' => intval($productId),
42 'operation' => 'اضافه کردن �
43 حصول به باسلا�
44 ',
45 ]);
46 wp_send_json_error(['message' => $e->getMessage()], 500);
47 }
48 if (!$result['success']) {
49 wp_send_json_error(['message' => $result['message']], $result['status_code'] ?? 500);
50 }
51
52 wp_send_json_success(['message' => $result['message']], $result['status_code'] ?? 200);
53 }
54 }
55