| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Services\Products; |
| 4 |
|
| 5 |
use SyncBasalam\Utilities\ProductMetaKey; |
| 6 |
|
| 7 |
class ConnectSingleProductService |
| 8 |
{ |
| 9 |
public static function connectProductById($wooProductId, $syncBasalamProductId) |
| 10 |
{ |
| 11 |
$existingPosts = get_posts([ |
| 12 |
'post_type' => 'product', |
| 13 |
'meta_query' => [ |
| 14 |
[ |
| 15 |
'key' => ProductMetaKey::basalamProductId(), |
| 16 |
'value' => $syncBasalamProductId, |
| 17 |
], |
| 18 |
], |
| 19 |
'posts_per_page' => 1, |
| 20 |
'fields' => 'ids', |
| 21 |
]); |
| 22 |
|
| 23 |
if (!$existingPosts) { |
| 24 |
update_post_meta($wooProductId, ProductMetaKey::basalamProductId(), $syncBasalamProductId); |
| 25 |
update_post_meta($wooProductId, ProductMetaKey::basalamProductStatus(), 2976); |
| 26 |
update_post_meta($wooProductId, ProductMetaKey::basalamProductSyncStatus(), 'synced'); |
| 27 |
|
| 28 |
return true; |
| 29 |
} else return false; |
| 30 |
} |
| 31 |
} |
| 32 |
|