# sync-basalam/1.9.0/includes/Services/Products/FetchUnsyncProducts.php

ووسلام – همگام سازی ووکامرس و باسلام, version 1.9.0. 52 lines.

- Page: https://pluginprobe.com/plugins/sync-basalam/1.9.0/code/includes/Services/Products/FetchUnsyncProducts.php
- Raw: https://pluginprobe.com/plugins/sync-basalam/1.9.0/raw/includes/Services/Products/FetchUnsyncProducts.php
- Modified: 2026-06-21T07:48:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/sync-basalam/1.9.0/code/includes/Services/Products/FetchUnsyncProducts.php#L10-L20`.

```php
<?php

namespace SyncBasalam\Services\Products;

use SyncBasalam\Utilities\ProductMetaKey;

defined('ABSPATH') || exit;

class FetchUnsyncProducts
{
    private $getProductsService;

    public function __construct()
    {
        $this->getProductsService = new FetchProductsData();
    }

    public function getUnsyncBasalamProducts($cursor = null, &$nextCursor = null)
    {
        $currentCursor = $cursor;

        while (true) {
            $productData = $this->getProductsService->getProductData(null, $currentCursor);
            $nextCursor = $productData['next_cursor'] ?? null;

            $basalamProducts = isset($productData['data']) && is_array($productData['data']) ? $productData['data'] : [];
            if (empty($basalamProducts)) return [];

            $products = [];

            foreach ($basalamProducts as $product) {
                if (!is_array($product) || empty($product['id'])) continue;

                if (!get_posts([
                    'post_type'  => 'product',
                    'meta_key'   => ProductMetaKey::basalamProductId(),
                    'meta_value' => $product['id'],
                    'fields'     => 'ids',
                ])) {
                    $products[] = $product;
                }
            }

            if (!empty($products)) return $products;

            if (empty($productData['has_more']) || $nextCursor === null) return [];

            $currentCursor = $nextCursor;
        }
    }
}

```
