| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | use SyncBasalam\Admin\Product\Operations\ArchiveProduct; |
| 8 | 8 | use SyncBasalam\Admin\Product\Operations\RestoreProduct; |
| 9 | 9 | use SyncBasalam\Jobs\Exceptions\RetryableException; |
| 10 | 10 | use SyncBasalam\Jobs\Exceptions\NonRetryableException; |
| 11 | -use SyncBasalam\Utilities\ProductMetaKey; | |
| 11 | +use SyncBasalam\Services\Products\ProductConnection; | |
| 12 | 12 | |
| 13 | 13 | defined('ABSPATH') || exit; |
| 14 | 14 | |
| 15 | 15 | class ProductOperations |
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | throw $e; |
| 40 | 40 | } catch (NonRetryableException $e) { |
| 41 | 41 | throw $e; |
| 42 | 42 | } catch (\Exception $e) { |
| 43 | - throw new \Exception($e->getMessage()); | |
| 43 | + throw new \Exception(esc_html($e->getMessage())); | |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function createNewProduct($product_id, $category_ids) |
| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | throw $e; |
| 53 | 53 | } catch (NonRetryableException $e) { |
| 54 | 54 | throw $e; |
| 55 | 55 | } catch (\Exception $e) { |
| 56 | - throw new \Exception($e->getMessage()); | |
| 56 | + throw new \Exception(esc_html($e->getMessage())); | |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function restoreExistProduct($product_id) |
| @@ -65,9 +65,9 @@ | ||
| 65 | 65 | throw $e; |
| 66 | 66 | } catch (NonRetryableException $e) { |
| 67 | 67 | throw $e; |
| 68 | 68 | } catch (\Exception $e) { |
| 69 | - throw new \Exception($e->getMessage()); | |
| 69 | + throw new \Exception(esc_html($e->getMessage())); | |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function archiveExistProduct($product_id) |
| @@ -78,9 +78,9 @@ | ||
| 78 | 78 | throw $e; |
| 79 | 79 | } catch (NonRetryableException $e) { |
| 80 | 80 | throw $e; |
| 81 | 81 | } catch (\Exception $e) { |
| 82 | - throw new \Exception($e->getMessage()); | |
| 82 | + throw new \Exception(esc_html($e->getMessage())); | |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| @@ -87,22 +87,9 @@ | ||
| 87 | 87 | public static function disconnectProduct($product_id) |
| 88 | 88 | { |
| 89 | 89 | do_action('sync_basalam_before_disconnect_product', $product_id); |
| 90 | 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 | - } | |
| 91 | + ProductConnection::purge($product_id); | |
| 105 | 92 | |
| 106 | 93 | $result = [ |
| 107 | 94 | 'success' => true, |
| 108 | 95 | 'message' => 'اتصال محصولات با موفقیت حذف شد.', |