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); $syncFields = syncBasalamSettings()->getSettings(\SyncBasalam\Admin\Settings\SettingsConfig::SYNC_PRODUCT_FIELDS); $strategy = 'create'; if ($isUpdate) { if ($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); } }