We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Members credits

  • discuss.answer
    • 3749
    • 24,544 Posts
    That sounds right to me, and if the event Extra has the ability to use hooks, you won't need to modify its code.

    If necessary, you can make the number of credits to add or subtract and whether to add or subtract them properties in the snippet tag. So the code might look something like this:

    In the tag:
    &credits=`10` &method=`add` (or &method=`subtract`)


    In the snippet or hook:

    $change = $modx->getOption('credits', $scriptProperties);
    $method = $modx->getOption('method', $scriptProperties);
    
    $profile = $modx->user->getOne('Profile');
    if ($profile) {
        $currentCredits = $profile->get('fax');
        if ($method == 'add') {
            $newCredits = $currentCredits + $change;
        } else {
            $newCredits = $currentCredits = $change;
        }
        $profile->set('fax', $newCredits);
        $profile->save();
    }


    You could also put the method and credits in TVs with those name and change the first two lines to these:

    $change = $modx->resource->getTVValue('credits');
    $method = $modx->resource->getTVValue('method');
    
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting