Files
2026-09-09 16:56:22 +07:00

28 lines
824 B
PHP

<?php
namespace App\Integrations\Whmcs\Support;
use Illuminate\Support\Facades\DB;
/** Resolves a WHMCS `tblproducts.id` to the local `products.id` via `legacy_id`. */
class ProductIdResolver
{
/** @var array<int, int>|null */
private static ?array $map = null;
public function resolve(int $legacyProductId): ?int
{
self::$map ??= DB::table('products')->whereNotNull('legacy_id')->pluck('id', 'legacy_id')->all();
return self::$map[$legacyProductId] ?? null;
}
public function categoryTypeOf(int $localProductId): ?string
{
return DB::table('products')
->join('product_categories', 'product_categories.id', '=', 'products.product_categories_id')
->where('products.id', $localProductId)
->value('product_categories.type');
}
}