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 / Admin / Product / ProductOperations.php

ProductOperations.php in ووسلام – همگام سازی ووکامرس و باسلام 1.8.6, at includes/Admin/Product/ProductOperations.php

121 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\Product;
4
5 use SyncBasalam\Admin\Product\Operations\UpdateProduct;
6 use SyncBasalam\Admin\Product\Operations\CreateProduct;
7 use SyncBasalam\Admin\Product\Operations\ArchiveProduct;
8 use SyncBasalam\Admin\Product\Operations\RestoreProduct;
9 use SyncBasalam\Jobs\Exceptions\RetryableException;
10 use SyncBasalam\Jobs\Exceptions\NonRetryableException;
11 use SyncBasalam\Utilities\ProductMetaKey;
12
13 defined('ABSPATH') || exit;
14
15 class ProductOperations
16 {
17 private $updateOperation;
18 private $createOperation;
19 private $archiveOperation;
20 private $restoreOperation;
21
22 public function __construct(
23 $updateOperation = null,
24 $createOperation = null,
25 $archiveOperation = null,
26 $restoreOperation = null
27 ) {
28 $this->updateOperation = $updateOperation ?: syncBasalamContainer()->get(UpdateProduct::class);
29 $this->createOperation = $createOperation ?: syncBasalamContainer()->get(CreateProduct::class);
30 $this->archiveOperation = $archiveOperation ?: syncBasalamContainer()->get(ArchiveProduct::class);
31 $this->restoreOperation = $restoreOperation ?: syncBasalamContainer()->get(RestoreProduct::class);
32 }
33
34 public function updateExistProduct($product_id, $category_ids = null)
35 {
36 try {
37 return $this->updateOperation->execute($product_id, ['category_ids' => $category_ids]);
38 } catch (RetryableException $e) {
39 throw $e;
40 } catch (NonRetryableException $e) {
41 throw $e;
42 } catch (\Exception $e) {
43 throw new \Exception($e->getMessage());
44 }
45 }
46
47 public function createNewProduct($product_id, $category_ids)
48 {
49 try {
50 return $this->createOperation->execute($product_id, ['category_ids' => $category_ids]);
51 } catch (RetryableException $e) {
52 throw $e;
53 } catch (NonRetryableException $e) {
54 throw $e;
55 } catch (\Exception $e) {
56 throw new \Exception($e->getMessage());
57 }
58 }
59
60 public function restoreExistProduct($product_id)
61 {
62 try {
63 return $this->restoreOperation->execute($product_id);
64 } catch (RetryableException $e) {
65 throw $e;
66 } catch (NonRetryableException $e) {
67 throw $e;
68 } catch (\Exception $e) {
69 throw new \Exception($e->getMessage());
70 }
71 }
72
73 public function archiveExistProduct($product_id)
74 {
75 try {
76 return $this->archiveOperation->execute($product_id);
77 } catch (RetryableException $e) {
78 throw $e;
79 } catch (NonRetryableException $e) {
80 throw $e;
81 } catch (\Exception $e) {
82 throw new \Exception($e->getMessage());
83 }
84 }
85
86
87 public static function disconnectProduct($product_id)
88 {
89 do_action('sync_basalam_before_disconnect_product', $product_id);
90
91 $metaKeysToRemove = ProductMetaKey::basalamProductMetaKeys();
92
93 foreach ($metaKeysToRemove as $metaKey) {
94 delete_post_meta($product_id, $metaKey);
95 }
96
97 $product = wc_get_product($product_id);
98
99 if ($product && $product->is_type('variable')) {
100 $variationIds = $product->get_children();
101 foreach ($variationIds as $variationId) {
102 delete_post_meta($variationId, 'sync_basalam_variation_id');
103 }
104 }
105
106 $result = [
107 'success' => true,
108 'message' => 'اتصال �
109 حصولات با �
110 وفقیت حذف شد.',
111 'status_code' => 200,
112 ];
113
114 $result = apply_filters('sync_basalam_disconnect_product_result', $result, $product_id);
115
116 do_action('sync_basalam_after_disconnect_product', $result, $product_id);
117
118 return $result;
119 }
120 }
121