# sync-basalam/1.10.13/includes/Admin/Product/Data/ProductDataFacade.php

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

- Page: https://pluginprobe.com/plugins/sync-basalam/1.10.13/code/includes/Admin/Product/Data/ProductDataFacade.php
- Raw: https://pluginprobe.com/plugins/sync-basalam/1.10.13/raw/includes/Admin/Product/Data/ProductDataFacade.php
- Modified: 2026-09-01T11:49:02+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.10.13/code/includes/Admin/Product/Data/ProductDataFacade.php#L10-L20`.

```php
<?php

namespace SyncBasalam\Admin\Product\Data;

use SyncBasalam\Admin\Product\Data\Validators\ValidatorChain;
use SyncBasalam\Admin\Product\Data\Validators\ImageValidator;
use SyncBasalam\Admin\Product\Data\Validators\ProductExistenceValidator;
use SyncBasalam\Admin\Product\Data\Validators\ProductStatusValidator;
use SyncBasalam\Admin\Product\Data\Validators\WeightValidator;
use SyncBasalam\Admin\Product\ProductDataFactory;
use SyncBasalam\Admin\Settings\SettingsConfig;
use SyncBasalam\Admin\Settings\SettingsManager;
use SyncBasalam\Jobs\Exceptions\NonRetryableException;
use SyncBasalam\Services\VendorSyncPolicy;
use SyncBasalam\Utilities\ProductMetaKey;

defined('ABSPATH') || exit;

class ProductDataFacade
{
    private static $builder = null;
    private static $factory = null;
    private static $validator = null;

    private static function initialize(): void
    {
        if (self::$builder === null) {
            self::$factory = new ProductDataFactory();
            self::$validator = new ValidatorChain();

            self::$validator->add(new ProductExistenceValidator())
                ->add(new ProductStatusValidator())
                ->add(new ImageValidator())
                ->add(new WeightValidator());

            self::$builder = new ProductDataBuilder(self::$validator, self::$factory);
        }
    }

    public static function get(int $productId, ?array $categoryIds = null): array
    {
        self::initialize();

        $product = wc_get_product($productId);
        if (!$product) throw new \InvalidArgumentException(esc_html("Product with ID {$productId} not found"));

        $basalamProductId = get_post_meta($productId, ProductMetaKey::basalamProductId(), true);
        $isUpdate = !empty($basalamProductId);

        $settings = SettingsManager::getSettings();
        $syncFields = $settings[SettingsConfig::SYNC_PRODUCT_FIELDS] ?? 'all';
        $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class);

        if (
            $isUpdate
            && !$vendorSyncPolicy->shouldRestrictUpdateFields(false)
            && !SettingsManager::isProductUpdateSelectionValid($settings)
        ) {
            throw NonRetryableException::invalidData(SettingsConfig::CUSTOM_PRODUCT_UPDATE_REQUIRED_MESSAGE);
        }

        $strategy = 'create';
        if ($isUpdate) {
            if ($vendorSyncPolicy->shouldRestrictUpdateFields() || $syncFields === 'price_stock') $strategy = 'quick_update';
            elseif ($syncFields === 'custom') $strategy = 'custom_update';
            else $strategy = 'update';
        }

        return self::$builder
            ->reset()
            ->setStrategy(self::$factory->createStrategy($strategy))
            ->fromWooProduct($productId)
            ->withCategoryIds($categoryIds)
            ->build();
    }

    public static function validateProduct($product): void
    {
        self::initialize();
        self::$validator->validate($product);
    }
}

```
