<?php

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

function smarty_function_get_pricelevel($params, &$smarty)
{
    $service = ServiceContainer::getService(KupShop\CatalogBundle\PriceLevel::class);
    $pl = $service->createFromDB($params['id']);

    // kdyz pl neexistuje tak mi createFromDB vrati praznej objekt pouze s nastavenym id, v takovem pripade chci vratit ciste "null"
    if (!$pl->unit) {
        $pl = null;
    }

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