<?php

function smarty_function_price_converter($params, &$smarty)
{
    if (empty($params['price']) || empty($params['from']) || empty($params['to'])) {
        throw new InvalidArgumentException('Missing required parameters \'price\' or \'from\' or \'to\'');
    }

    $priceConverter = \KupShop\KupShopBundle\Util\Compat\ServiceContainer::getService(\KupShop\I18nBundle\Util\PriceConverter::class);

    $result = $priceConverter->convert($params['from'], $params['to'], $params['price']);

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