<?php

function smarty_function_get_filter_prices($params, $smarty)
{
    $products = $params['products'] ?? [];

    $prices = [];
    foreach ($products->getValues() ?? [] as $value) {
        $prices[] = $value->getProductPrice()->getPriceWithVat()->asFloat() ?? 0;
    }

    $result = false;
    if (!empty($prices)) {
        $result = [
            'min' => min($prices) ?? 0,
            'max' => max($prices) ?? 0,
        ];
    }

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
