<?php

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\OrderingBundle\Util\Order\OrderInfo;

function smarty_function_get_order_items_discounts($params, &$smarty)
{
    if (empty($params['order'])) {
        throw new InvalidArgumentException("Missing parameter 'order' in smarty function 'get_order_items_discounts'!");
    }

    $order = $params['order'];
    $orderInfo = ServiceContainer::getService(OrderInfo::class);

    $itemsDiscounts = $orderInfo->getDiscounts($order);

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