<?php

function smarty_function_get_order_box($params, &$smarty)
{
    if (empty($params['id_order'])) {
        throw new InvalidArgumentException();
    }

    $position = sqlQueryBuilder()->select('wpos.code as box_position')
        ->from('warehouse_orders', 'wo')
        ->join('wo', 'warehouse_positions', 'wpos', 'wpos.id = wo.id_position')
        ->andWhere(\Query\Operator::equals(['wo.id_order' => $params['id_order']]))
        ->execute()->fetchColumn();

    if (!$position) {
        $position = null;
    }

    $assign = getVal('assign', $params);
    if (!empty($assign)) {
        $smarty->assign($assign, $position);
    } else {
        return $position;
    }
}
