<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     get_serie
 * Purpose:  get a serie of known product id
 * -------------------------------------------------------------
 */
function smarty_function_get_serie($params, &$smarty)
{
    extract($params);

    if (empty($params['id_product'])) {
        return;
    }

    $serie = sqlFetchArray(sqlQueryBuilder()->select('ab_s.*')
        ->from('products', 'p')
        ->leftJoin('p', 'abra_models', 'abm', 'abm.id_abra = p.id_model')
        ->leftJoin('abm', 'abra_series', 'ab_s', 'abm.id_serie = ab_s.id_abra')
        ->where(\Query\Operator::equals(['p.id' => $params['id_product']]))
        ->execute());

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