Skip to content
Code-Schnipsel Gruppen Projekte
setUserCurrency.php 684 B
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    /**
     * This file contains package_quiqqer_currency_ajax_setUserCurrency
     */
    
    /**
     * Set the user currency
     */
    QUI::$Ajax->registerFunction(
        'package_quiqqer_currency_ajax_setUserCurrency',
        function ($currency) {
            $allowed = QUI\ERP\Currency\Handler::getAllowedCurrencies();
            $allowed = \array_map(function ($Currency) {
                return $Currency->getCode();
            }, $allowed);
    
    
            $allowed = array_flip($allowed);
    
    
            if (!isset($allowed[$currency])) {
                return;
            }
    
            $User = QUI::getUserBySession();
            $User->setAttribute('quiqqer.erp.currency', $currency);
            $User->save();
        },
        ['currency']
    );