<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     getFormatedPrice
 * Purpose:  get formated price for google analytics
 * -------------------------------------------------------------
 */
/**
 * @param array  $params
 * @param Smarty $smarty
 *
 * @return array
 */
function smarty_function_get_formated_price($params, &$smarty)
{
    if (empty($params['price'])) {
        return '';
    }

    $params['price'] = unapplyCurrency($params['price']);

    if (!empty($params['sub'])) {
        $params['price'] = $params['price']->sub($params['sub']);
    }

    if ($params['price']->isZero()) {
        return '0';
    }

    return str_replace(',', '.', str_replace(' ', '', $params['price']->printValue(2)));
}
