<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     eval
 * Purpose:  evaluate a template variable as a template
 * -------------------------------------------------------------
 */

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\ParameterGroupsBundle\Util\ParameterGroupsUtil;

function smarty_function_get_product_parameter_group($params, &$smarty)
{
    if (empty($params['id_product'])) {
        trigger_error('get_product_parameter_group: missing id_product!');

        return [];
    }

    $parameterGroupsUtil = ServiceContainer::getService(ParameterGroupsUtil::class);
    $result = $parameterGroupsUtil->getParameterGroups($params['id_product']);

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