Source self-serve lane products from published config
This commit is contained in:
@@ -7,6 +7,7 @@ use classes\object_property;
|
||||
use classes\selfserve;
|
||||
use classes\selfserve_schema_bootstrap;
|
||||
use Exception;
|
||||
use modules\selfserve\classes\selfserve_config_versioning;
|
||||
use traits\db_object_t;
|
||||
|
||||
class department_lanes_o extends db
|
||||
@@ -324,9 +325,52 @@ class department_lanes_o extends db
|
||||
public function getSelfServeLaneProducts(): array
|
||||
{
|
||||
self::requireSelected();
|
||||
$publishedProducts = $this->getPublishedSelfServeLaneProducts();
|
||||
if ($publishedProducts !== []) {
|
||||
return $publishedProducts;
|
||||
}
|
||||
|
||||
return department_selfserve_tasks_o::getLaneProducts((int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
private function getPublishedSelfServeLaneProducts(): array
|
||||
{
|
||||
try {
|
||||
$published = (new selfserve_config_versioning())->getPublishedV2Config((int)$this->department->value());
|
||||
} catch (\Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$config = is_array($published['config'] ?? null) ? $published['config'] : null;
|
||||
if ($config === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$laneId = (int)$this->id;
|
||||
$products = [];
|
||||
foreach ((array)($config['tasks'] ?? []) as $task) {
|
||||
if (!is_array($task)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$taskLane = (int)($task['lane'] ?? 0);
|
||||
if ($taskLane !== 0 && $taskLane !== $laneId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$productId = (int)($task['product'] ?? 0);
|
||||
if ($productId > 0 && !in_array($productId, $products, true)) {
|
||||
$products[] = $productId;
|
||||
}
|
||||
}
|
||||
|
||||
sort($products, SORT_NUMERIC);
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return department_lanes_o[] An array of department lane objects for the specified department
|
||||
|
||||
Reference in New Issue
Block a user