| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Services; |
| 4 |
|
| 5 |
use SyncBasalam\Utilities\ProductMetaKey; |
| 6 |
|
| 7 |
defined('ABSPATH') || exit; |
| 8 |
|
| 9 |
class ProductDisconnectService |
| 10 |
{ |
| 11 |
public function disconnectSelected(array $productIds): void |
| 12 |
{ |
| 13 |
foreach ($productIds as $productId) { |
| 14 |
$this->disconnectSingle($productId); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
private function disconnectSingle(int $productId): void |
| 19 |
{ |
| 20 |
$metaKeysToRemove = [ |
| 21 |
ProductMetaKey::basalamProductId(), |
| 22 |
ProductMetaKey::basalamProductSyncStatus(), |
| 23 |
ProductMetaKey::basalamProductStatus(), |
| 24 |
]; |
| 25 |
|
| 26 |
foreach ($metaKeysToRemove as $metaKey) { |
| 27 |
delete_post_meta($productId, $metaKey); |
| 28 |
} |
| 29 |
|
| 30 |
$this->disconnectVariations($productId); |
| 31 |
} |
| 32 |
|
| 33 |
private function disconnectVariations(int $productId): void |
| 34 |
{ |
| 35 |
$product = wc_get_product($productId); |
| 36 |
|
| 37 |
if ($product && $product->is_type('variable')) { |
| 38 |
$variationIds = $product->get_children(); |
| 39 |
|
| 40 |
foreach ($variationIds as $variationId) { |
| 41 |
delete_post_meta($variationId, 'sync_basalam_variation_id'); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|