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:
@@ -22,7 +22,7 @@ if (!function_exists('add_hook_os_templates')) {
|
|||||||
$cs = new ConfigureService();
|
$cs = new ConfigureService();
|
||||||
|
|
||||||
$templates_data = $cs->fetchTemplates(
|
$templates_data = $cs->fetchTemplates(
|
||||||
$cs->fetchPackageId($vars['productinfo']['name'])
|
$cs->fetchPackageByDbId($vars['productinfo']['pid']) ?? $cs->fetchPackageId($vars['productinfo']['name'])
|
||||||
);
|
);
|
||||||
|
|
||||||
if (empty($templates_data)) {
|
if (empty($templates_data)) {
|
||||||
@@ -72,7 +72,6 @@ if (!function_exists('add_hook_os_templates')) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$configurableoptions = $vars['configurableoptions'];
|
$configurableoptions = $vars['configurableoptions'];
|
||||||
|
|
||||||
array_push(
|
array_push(
|
||||||
$configurableoptions,
|
$configurableoptions,
|
||||||
$osTemplates,
|
$osTemplates,
|
||||||
|
|||||||
@@ -43,13 +43,33 @@ class ConfigureService extends Module
|
|||||||
return null;
|
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
|
* @param int $serverPackageId
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @throws JsonException
|
* @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']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
$response = $request->get(
|
$response = $request->get(
|
||||||
|
|||||||
Reference in New Issue
Block a user