Check the database first to see if the ID has been set, otherwise, fallback to querying the API based on product name.

This commit is contained in:
2023-09-10 20:56:53 -04:00
parent 07f3c69977
commit bb2e8ac538
2 changed files with 22 additions and 3 deletions

View File

@@ -43,13 +43,33 @@ class ConfigureService extends Module
return null;
}
/**
* @param int $productId
* @return int|null
*/
public function fetchPackageByDbId(int $productId): ?int
{
$product = DB::table('tblproducts')->where('id', $productId)->first();
if (is_null($product)) {
return null;
}
return (int)$product->configoption2;
}
/**
* @param int $serverPackageId
* @return array|null
* @throws JsonException
*/
public function fetchTemplates(int $serverPackageId): ?array
public function fetchTemplates(?int $serverPackageId): ?array
{
if (is_null($serverPackageId)) {
return null;
}
$request = $this->initCurl($this->cp['token']);
$response = $request->get(